Android – the startactivity in onpause() is invalid after opening a new app

When my first activity is suspended, I start my second activity

FirstActivity.java

@Override
public void onPause(){
    super.onPause();
    startActivity(new Intent(this, SecondActivity.class));
}

When I press the home button, secondactivity will start, but there will be a delay. In this delay, there is enough time to open a new application (such as messenger). However, when I open a new application, secondactivity will no longer start (it will not even call the oncreate method of secondactivity)

How can I start secondactivity even if I open a new application?

resolvent:

Instead of adding code to onpause (), override the onbackpressed () method and start a new activity from there

@Override
public void onBackPressed()
{
    startActivity(new Intent(this, SecondActivity.class));
    super.onBackPressed();
}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>