0

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.

Community
  • 1
  • 1
Bruno Saboia
  • 332
  • 3
  • 18

3 Answers3

2

Have you tried calling Activity.finish() ?

K-ballo
  • 80,396
  • 20
  • 159
  • 169
  • Yes. Activity.finish() do not "closes" the application. As a matter of fact, it is the same thing of pressing the back button. The Android OS handles the process, which is not what I want, I want to destroy the app. – Bruno Saboia Sep 08 '11 at 21:40
  • if you want to do something before app closes, you can always do so in onBackPressed. – Vaibhav Mishra Nov 17 '11 at 12:40
0

Try this......

System.exit(0);
Noby
  • 6,562
  • 9
  • 40
  • 63
  • Thanks, but System.exit is close to android.os.Process.killProcess(android.os.Process.myPid()); in terms of hacking. The app closes in a way that the user can think that it crashed, and that's what I'm trying to avoid. – Bruno Saboia Sep 09 '11 at 17:56
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..

Karan_Rana
  • 2,813
  • 2
  • 26
  • 35
  • Thanks for the help, but this didn't work as well. Everytime my app starts, it connects to the login server and retrieves some data. I've put what you told under the application tag in the manifest, but it is the same thing: if i hit the back button and then come back to the application, all the data that was downloaded from the server appears on the main screen, which is not what i want. This data is private, hence a logout should mean that no one is able to see that info again, unless they do a login. – Bruno Saboia Sep 09 '11 at 18:01
  • you have to put the above tag in every activity tag of your application...not in the application tag – Karan_Rana Sep 10 '11 at 08:01
  • Okay, I will test and post results, K-ran. But I have just one Activity. – Bruno Saboia Sep 12 '11 at 12:43
  • That did not work. What I did: In the Manifest file, `` In the MainActivity.java file, `private void Logout() { Toast.makeText(this, "User logged off", Toast.LENGTH_SHORT).show(); FragmentLayout.this.finish(); }` Of course, I have a button that calls logoff. I can see the toast in the screen. – Bruno Saboia Sep 12 '11 at 18:13