Restart app to a certain activity?

醉酒当歌 提交于 2019-12-01 02:33:58
Lukap

In the onCreate method of the activity that is first launched you need to check if you want to go to another activity or not and then

where restarted is some condition that check if your app was running before , you can use shared preferences to store some bool value

if(restarted){

        Intent startActivity = new Intent();
        startActivity.setClass(this,OTHER_ACTIVITY.class);
        startActivity(startActivity); 
        finish();
}else{
   //just normal flow
}

You have to start the Activity you wish straight from the initial Activity's onCreate(). As this is only applicable when the app restarts, you have to save a SharedPreference to flag the fact your app has already started once.

There won't be any flickering as Activity is designed in a way it is not displayed if another Activity is started during its onCreate().

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