coffee
coffee

Reputation: 3088

Kill and destroy activity

The first screen of my application is a login screen, so I used the method finish () after user have logged. However when i return the application I would like to be already logged. I tried to use onDestroy (), but without success.

Upvotes: 0

Views: 905

Answers (3)

tmho
tmho

Reputation: 1508

You might want to have a look at the Activity Life Cycle... Furthermore SharedPreferences can be used to save username/login details but im of the understanding that they can be accessed by any application, so be careful what you put there.

Upvotes: 0

Mojo Risin
Mojo Risin

Reputation: 8142

It'll be better if you implement your logic otherwise. The first screen in your application can be HomeScreenActivity in which you'll check if the user is logged and start LoginActivity if needed.

public class HomeScreenActivity extends Activity {

    /* some declaration */
    public void onCreate(Bundle savedInstanceState) {
        /* some other stuff */
        if (!userIsLogged()) {
            Intent intent = new Intent(this,LoginActivity.class);
            startActivity(intent);
        }
    }
}

Upvotes: 2

lcoq
lcoq

Reputation: 10726

You have to use SharedPreferences.

See Data Storage on Android Developer

Upvotes: 1

Related Questions