[英]starting a service at boot time taking too much time,why?
我正在嘗試構建一個啟動顯示視圖的服務的應用程序。 我想做的是在啟動后立即顯示視圖,但是啟動服務花費了太多時間(> 1分鍾)。 我的廣播接收器:
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
Intent intentservice = new Intent(context,NewService.class);
try{
context.startService(intentservice);
}
catch(Exception e){
e.printStackTrace();
}
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
Intent intent11 = new Intent(context,MainActivity.class);
intent11.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
else if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
{
context.startService(new Intent(context,NewService.class));
}
表現:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<service android:name="com.example.p.NewService"></service>
<receiver android:name="receiver.myReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.SCREEN_OFF" />
<action android:name="android.intent.action.SCREEN_ON" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
如何進行? 有什么辦法可以設置優先級?
內部接收者替換權限為:
<intent-filter android:priority="1000">
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
這應該加快速度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.