Reputation: 161
I'm trying to build an app that starts an service which displays a View. What I am trying to do is to display the view quickly just after the boot but its takes too much time(>1min) to start the service. My BroadcastReceiver:
@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));
}
Manifest:
<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>
how to proceed? Is there any way to set priority or something like that?
Upvotes: 0
Views: 994
Reputation: 2130
Inside receiver replace permission with:
<intent-filter android:priority="1000">
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
This should speed up things.
Upvotes: 2