Application is not starting on device boot

混江龙づ霸主 提交于 2019-12-01 11:49:45
m0skit0

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);
    }
}

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);

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!