Aishvarya Jaiswal
Aishvarya Jaiswal

Reputation: 1811

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

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?

Upvotes: 6

Views: 720

Answers (2)

Bonatti
Bonatti

Reputation: 2781

While Ninjas answer provided a way to close many activities on stack, note that the way Android was built, no application may interact directly with another... this as a security feature blocks most un wanted software, as well as malwares/virus/etc.

The only actual way to forcefully close an application is to either block resources for it (by using the Android Settings tool to put the application in "not started" state), or to go to the below system (mostly a linux), and deny resources, this one is tricker, but possible.

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?

It is the OS "fault", but it behaves EXACTLY as expected. No program should be able to alter/edit your program. Just like ninjas answer, he basically asked the system to disregard any activities on that stack. But if muliple stacks are present... well... nope then, its the APP fault.

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?

A programmer should NOT exit his application, because its not a full program, you are basically running commands inside another program, hence the rules must be obeyed. Once you start, the memory management is out of your hands, so you cannot/should not "exit" applications.

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

Dont understand this one. In the application lifecycle, everything is either behaving normally (or you know, stopped: example has stopped working), or in the ready state

Upvotes: 0

Lazy Ninja
Lazy Ninja

Reputation: 22537

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
}

Upvotes: 1

Related Questions