Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Killing an application, is Android going the right way in this process.?

Tags:

android

I have seen many task killer apps, which claim to kill the apps in background, but once I use them, I find out that what they do is just vanish the apps from their list view and fool the user that they are killed.

If I open the same task killer app again within seconds, the same app will again be there which was claimed to be killed earlier. Now is this a fault of the app or the Android OS?

Not only here, even with apps having an Exit option, I have noticed that clicking the exit button does not terminate it. So where is the problem?

Long ago I read that there is no function provided in Android to kill an app (I don't know about current time). So shall the blame be given to the OS? Is there a proper way yet to close an app when we want and make it behave normally?

like image 369
Akshat Avatar asked Nov 26 '13 06:11

Akshat


1 Answers

Not only here, even with apps having Exit option, I have noticed that clicking the exit button does not terminate it. So where is the problem.?

If the application is designed properly, the exit option should kill it. But having an Exit option is frowned up in Android.
You can kill an activity using finish(). An application is a combination of activities, so if all activities are properly killed, the application wont be running in my understanding. I could be wrong though.

Long ago I read that there is no function provided in Android to kill an app (don't know about current time). So shall the blame be given to the OS.?

From what I know there is not an official to kill an application at once. But there are some hacks which allows you to kill all the activities at once.

Is there a proper way yet to close an app when we want and make it behave normally.?

Well the following hack works well for me.

Close all the previous activities as follows:

Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("Exit me", true);
startActivity(intent);
finish();

Then in MainActivity onCreate() method add this to finish the MainActivity

setContentView(R.layout.main_layout);

if( getIntent().getBooleanExtra("Exit me", false)){
    finish();
    return; // add this to prevent from doing unnecessary stuffs
}
like image 154
Lazy Ninja Avatar answered Oct 19 '22 12:10

Lazy Ninja