安卓:多重活动和的OnDestroy问题 [英] Android: Multiple Activities and OnDestroy Question

查看:178
本文介绍了安卓:多重活动和的OnDestroy问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几十个活动:1主,1 - 动画,10其他的和它的子集更多的活动(几十个的)

从主,你可以去任何的其他的通过按钮。

其他的调用的子集的活动和他们所说的动画活动。

每个活动,包括子集和动画,有一个按钮,返回到主活动。

所有按钮都需要用户纠正活动。

问题:从主要活动,我想通过使用设备的返回键退出。但是,什么情况是,它的步骤向后所有的previous活动。

回归主按钮(在每一项活动)具有的完成的,并在其中的的onDestroy 的。所以,我不知道为什么这些画面/活动不被破坏......?

任何意见/建议/说明是AP preciated - 谢谢

[加code片段]

注:我移动/添加/删除的结束,的onDestroy,的onStop ......试了很多办法等什么的片断显示了只有一个方法我试过了......

  // ------------------------------------ ---------------------
mainMenu.setOnClickListener(新View.OnClickListener(){
    公共无效的onClick(视图v){
        // 做一点事
        意图主要code =新意图();
          主要code.setClassName(
                              com.bt.test
                              com.bt.test.Main code);
        // startActivity(主要code); //进入主code
          完();
          的onStop();
        的onDestroy();
        startActivity(主要code); //进入主code
    }
}); // 结束  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - -
 

解决方案

你能将你的onClick处理程序返回主按钮?

您应该做这样的事情:

 意向书我=新的意图(这一点,MainActivity.class);
startActivity(ⅰ);
完();
 

编辑: 你也可以尝试设置该标志:

  i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 

此应该清除主叫和接收活动之间的活动堆栈如果接收活动已经是在堆栈的某个地方。

I have a few dozen activities: 1-Main, 1-Animation, 10-Other's and it's sub-sets of more activities (couple of dozen).

From the Main, you can go to any of the Others via buttons.

The Others call sub-set activities and they call the Animation activity.

Each of the activities, including sub-sets and Animation, has a button to return to the Main activity.

All buttons take user to correct activity.

The issue: From the Main activity, I want to quit via using the device's Back key. But, what happens is that it steps backward through all the previous activities.

The "return to main" buttons (in each activity) has finish and onDestroy in it. So, I'm not sure why those screen/activities aren't destroyed...?

Any comments/suggestions/clarifications is appreciated - thanks

[adding code snippet]

Note: I moved/added/deleted the finish, onDestroy, onStop... tried many ways so what shows in the snippet is only one way I tried...

    //  ---------------------------------------------------------
mainMenu.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        // do something
        Intent Maincode = new Intent();
          Maincode.setClassName(
                              "com.bt.test",
                              "com.bt.test.Maincode");
        //  startActivity(Maincode); // go to maincode  
          finish();
          onStop();
        onDestroy();
        startActivity(Maincode); // go to maincode  
    }
}); // end -----------------------------------------------

解决方案

Could you post your onClick handler for the return to main button?

You should be doing something like this:

Intent i = new Intent(this, MainActivity.class);
startActivity(i);
finish();

Edit: You could also try setting this flag:

i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

This should clear the activity stack between the calling and receiving activity if the receiving activity is already in the stack somewhere.

这篇关于安卓:多重活动和的OnDestroy问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆