简体   繁体   中英

Android application start-up

In my application,it requires to start the application from the starting activity or the first activity;as the application is authenticated by a login section..

So,whenever the application gets exit;say,via pressing BACK or HOME button,i need to start the application from the login itself...Is there any method to do the same?

I tried a simple technique by overriding the KEYEVENT,and implementing the finish() method inside.It works for the the BACK button;but its not working for the HOME button...

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_HOME) {

        finish();    
    }
    if (keyCode == KeyEvent.KEYCODE_BACK) {

        finish();    
    }
    return false;
}

take a look at this:

activity lifecycle

basically, everytime your application gets paused, you close the activity so it has to be restarted again. You can do this by overriding the onPause method and closing the activity there

如果我没记错的话,您将无法覆盖HOME按钮,因为它应该使用户能够在任何给定时间退出应用程序。

when HOME Key Pressed onStop is called so you can add finish(); in onStop() for destory Activity and you can try to use onUserLeaveHint() this method also called when user press Home key

Ya got the answer...

I just included the following attribute for the first activity to be displayed all the time,as i said in my question...

android:launchMode="singleTask"
android:clearTaskOnLaunch="true"

also include this attribute for the other activities...

android:finishOnTaskLaunch="true"

Just try......

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM