开发者

How to kill an application when the user taps a button

开发者 https://www.devze.com 2023-04-03 10:13 出处:网络
What I want basically is to have a logout button in the ActionBar, in such a way that when the user come back to the App, it will run as it 开发者_开发百科was the first time. I\'ve accomplished this e

What I want basically is to have a logout button in the ActionBar, in such a way that when the user come back to the App, it will run as it 开发者_开发百科was the first time. I've accomplished this exact behaviour calling:

android.os.Process.killProcess(android.os.Process.myPid()); 

on the Logout button handler, but I'm avoiding using such obscure hacks.

I've tried to do as described here Killing android application on pause , but the behaviour is not the expected. When the users come back, the application is already logged in. I must ensure that whenever the users log offs, the app will be reloaded the next time it runs.

I've also tried this: Android - How to start the exact same activity every time the app is opened up? . The behaviour is the same as finish()'ing on pause.

Please do not reply comment such as "why you want that, this is not how Android works, it manages the processes for you" and so on. I understand the lifecycle, as described here: http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle . What I want is not usual but absolutely necessary for the app I'm working with. If killing the process is the only answer, then unfortunatelly that is exactly what I'm going to do.


Have you tried calling Activity.finish() ?


Try this......

System.exit(0);


In Android....The OS maintain a Stack So when we finish one activity the previous activity comes in front.......So if you dont want to keep the stack then us the follwing line in every activity of your manifest file.

  **android:noHistory="true"**

Now you try to exit the application using exit button use the following code on Exit button:

**activity_name.this.finish();**

it will Work..

0

精彩评论

暂无评论...
验证码 换一张
取 消