简体   繁体   中英

How to handle minimised app back press?

I am not able to handle this below scenario. When I go to Activity B from Activity A and minimize the app and open from recent apps, Activity B will open and if I press back on Activity B, Activity A should resume, but in my case the app is closing.

Activity A

tool_setting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent mIntent = new Intent(Activity_A.this,
                        Activity_B.class);
                startActivity(mIntent);
            }
        });

After clicking on button, opens Activity B. On B, I minimize and open app from recent apps, again on B if I press back button on toolbar, app closes instead of resuming Activity A.

You will have to take care of your Back Stack . Without knowing your code, you might be closing (calling finish() ) your Activity A.

The only reason that it will happen is if you are calling finish() after startActivity().

Something like:

private void startActivityB()
{
    Intent startActivityBIntent = new Intent(mContext, ActivityB.class);
    startActivity(startActivityBIntent);
    finish();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM