简体   繁体   中英

android re-launching application as home button

After many hours of searching and reading articles I am not able to call my stopped application the same way as the home button is re-launching it. So I pressed home button and my application is stopped. And my service(from other package) can only start new instance of my application (main launching activity).

Context context = this.getBaseContext();
PackageManager pm = context.getPackageManager();
Intent appStartIntent = pm.getLaunchIntentForPackage("main.application");
appStartIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(appStartIntent);

If it is possible I would like to call onResume of my application from my service - I didn't achieve it.

I try also this in my activity :D ...

@Override
protected void onStop() {  
    super.onStop();
    super.onResume():
}

The best unworking solution - override home button

public boolean onKeyDown(int keyCode, KeyEvent event)
{       
    if (keyCode == KeyEvent.KEYCODE_BACK

Thank you very much for effort in advance.

No, don't do all that things! Please, read this . The only way for you to achive the goal is to leverage Activity lifecycle callbacks to save/restore state.

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