开发者

Home button in android?

In my application i have three activity. In my third activity if i click home button it comes to the android home screen(application still run in background i noticed by using Log statement). If i relaunch application then it start from first activity. How can i load it from third activity? Any开发者_运维百科one can give me your suggestion....

Thanks in advance....


if you click home button, the activity execute the method: onPause() -> onStop();
when you relaunch application, the activity will execute the method: onRestart() -> onStart() -> onResume() -> ....
control the activity through these methods. i wish it would help you.


Override the method below.

@Override
public void onAttachedToWindow()
{  
    Log.i("TESTE", "onAttachedToWindow");
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    super.onAttachedToWindow();  
}

With this method, the HOME Button stops working in this activity (only this activity). Then you just reimplement as it was a normal button event (the back button for instance).

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_HOME) {
    Log.i("TESTE", "BOTAO HOME");
    return true;
}
return super.onKeyDown(keyCode, event);    

}


No, it does not start from first activity. If you press the home button, and then start the activity by pressing the activity icon or via the long press on home (application switcher), it will continue the app on the activity you were on.

You might have switched on the "immediately destroy" flag in the development settings of the emulator, or you might have too little memory left, or you have killed the process yourself. In these cases the Android can destroy your activity. Then it will restart with the start activity.

RG

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜