简体   繁体   中英

How can i close my app which is still running in background after closing

My application is running normally and when I move on some new activity I used the code as

Intent start=new Intent(current activity.this,new activity.class);
                startActivityForResult(start, 0);
                finish(); 

and then when I have to move back to the earlier activity I used the following code

Intent start = new Intent(current activity.this,earlier activity.class);
                    startActivity(start);
                    finishActivity(0);

I think in this way the stack of the activities may be clear. And on click of the button or the phone back button I used the following code

Intent startMain = new Intent(Intent.ACTION_MAIN);
                startMain.addCategory(Intent.CATEGORY_HOME);
                startMain.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(startMain);

But my application is still running in the background. I also used the android:noHistory="true" app is killed from the background but message appered that app close forcefully. Simple finish(); moves to the last activity. I also seen the link Quitting an application - is that frowned upon? but I am new so did't get much. Please suggest me some way how can I deal with this.

I think in this way the stack of the activities may be clear

You are welcome to your opinion. startActivityForResult() is not designed for how you are using it.

And on click of the button or the phone back button I used the following code

I would fire anyone who worked for me who did this.

Please follow the Android design guidelines for proper handling of the BACK button -- while I do not agree with everything in there, it is much better than what you are doing. In the eyes of the user, BACK means back .

But my application is still running in the background

So long as you have not leaked any threads or services, your process will be running, but it will be consuming no significant CPU time. Android will terminate the process when it needs the RAM. This way, if the user elects to return to your application, or something else in your application needs to run (eg, AlarmManager event, broadcast Intent ), Android does not have to waste CPU time and battery life to fork another process.

Please suggest me some way how can I deal with this.

Just leave the process alone, and nobody will get hurt.

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