1

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.

Community
  • 1
  • 1
BraveGirl
  • 75
  • 6
  • 4
    Is there a reason you want to mess up the whole concept of resumable [tasks](http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html) and automatically managed application life-cycle? – zapl May 03 '12 at 16:02
  • I have total 8 activities and control moves from one to another. There is no special reason for that. – BraveGirl May 03 '12 at 16:06

1 Answers1

1

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 (e.g., 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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • is there any draw back of having the application in the background. Is that app running at the time ? – BraveGirl May 04 '12 at 08:40
  • @BraveGirl: "Is that app running at the time ?" -- that depends on what you mean by "running". If you have your own background threads still running, those will continue to do their work, and so finding a time to stop those threads is important. Beyond that, though, nothing much of your code will be executing. The primary cost to the user then is just the chunk of RAM that you are consuming, and Android will terminate your process as soon as it has a better use for that RAM. – CommonsWare May 04 '12 at 10:50
  • Yes I have use one thread for the timer in my application then how can I stop that thread. Can you please tell me how can I stop these threads properly. And running means it is in the background and I checked it from the task manager. – BraveGirl May 04 '12 at 13:20
  • @BraveGirl: "Yes I have use one thread for the timer in my application then how can I stop that thread." -- I cannot tell you *how* to stop that thread, as I do not know how your thread is set up. There are plenty of books on Java threading models. *When* to stop that thread would be when the user BACKs out of your app, or when your app moves to the background (see `onUserLeaveHint()`). – CommonsWare May 04 '12 at 13:26