Application is not starting on device boot

前端 未结 3 1700
猫巷女王i
猫巷女王i 2021-01-16 10:21

I used BroadcastReceiver to start my application on boot, but it is not starting

here is my code

Manifest code :



        
相关标签:
3条回答
  • 2021-01-16 10:39

    Yes, call startActivity:

    @Override
    public void onReceive(Context context, Intent intent) {
    
         Intent startActivityIntent = new Intent(context, MainActivity.class);
            startActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(startActivityIntent);
        }
    

    For More Refer this Link http://blog.burnayev.com/2009/08/android-development-how-to-launch.html

    0 讨论(0)
  • 2021-01-16 10:46

    Try starting an Activity as opposed to Service:-

    Intent i = new Intent(context, MainActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);
    
    0 讨论(0)
  • 2021-01-16 10:47

    You are using startService() and MainActivity is not a Service. You need to use startActivity() instead.

    public class MyBroadcastreceiver extends BroadcastReceiver 
    {
        @Override
        public void onReceive(Context context, Intent intent) 
        {
            Intent startActivityIntent = new Intent(context, MainActivity.class);
            startActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(startActivityIntent);
        }
    }
    
    0 讨论(0)
提交回复
热议问题