后退按钮不调用历史堆栈最后一项活动 [英] BackButton dont call last activity in history stack

查看:164
本文介绍了后退按钮不调用历史堆栈最后一项活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林有关于我的活动后退按钮这个错误。所有活动都有这个问题。当我preSS后退按钮它进入主屏幕,而不是在堆栈中最后一项活动。我的推杆日志消息,但在某些活动它不打印在LogCat中,本次活动张贴在这里红外​​打印记录。但它看起来像某种活动的方法内没有要走了。

有三个选项卡在我的应用程序,其中的一个延伸的ActivityGroup 而不是Acitivty。但我不认为它的​​问题,我已经删除了此选项卡,并持续发生。

所以我的问题是,我该如何解决这个问题,我怎么让它去最后一项活动,而不是去主屏幕?

其实它关系到最后的屏幕,它被调用。如果我把它在主屏幕上它关系到这一点,如果我把它称为主屏幕,在这里我把快捷方式和小部件就可以进入该屏幕。
而对于我在文档读过,就应该到最后在历史堆栈,这意味着该屏幕是在栈中,但没有我的活动。对吗?

香港专业教育学院试图把这个,但不工作的任何活动。它使goint到主屏幕。我不知道那是什么。

  @覆盖
    公共布尔的onkeydown(INT键code,KeyEvent的事件){
        如果(键code == KeyEvent.KEY code_BACK){
                完();
            返回true;
        }
        返回super.onKeyDown(键code,事件);
    }

我也试图与 onBack pressed()方法,但一无所获。而且,与其说我完成一个新的尝试意图并调用一些活动明确地,但没有太。

我不能把我的一切活动,因为这里有很多。结果
但这里有一个,也许如果有事情和这个作品,我可以对别人实施。谢谢你。

 公共类MyActivity延伸活动{    私人的ListView列表视图;
    私人ImageView的imgView;
    私人资源资源;
    私人绘制对象过渡;
    私人SimpleCursorAdapter适配器;
    私人DataHandlerDB处理程序;
    私人SQLiteDatabase分贝;
    私人OpenHelper帮手;    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        助手=新OpenHelper(本);
        DB = helper.getWritableDatabase();
        setBasicContent();    }    @覆盖
    公共无效调用onStart(){        super.onStart();
        助手=新OpenHelper(本);
        DB = helper.getWritableDatabase();
        setBasicContent();    }    @覆盖
    公共无效的onDestroy(){        super.onDestroy();
        DataHandlerDB.selectTopCalls(本).close();
        db.close();
        helper.close();    }    @覆盖
    公共无效的onPause(){        super.onPause();    }    @覆盖
    公共无效的onStop(){        super.onStop();
        DataHandlerDB.selectTopCalls(本).close();
        db.close();
        helper.close();    }    @覆盖
    保护无效onResume(){        super.onResume();
        setBasicContent();    }
    公共无效setBasicContent(){        列表视图=(ListView控件)findViewById(R.id.list_view);        光标C = DataHandlerDB.selectTopCalls(本);        c.moveToFirst();        startManagingCursor(C);        适配器=新SimpleCursorAdapter(这一点,R.layout.list_item,C,
                新的String [] {DataHandlerDB.CONTACT_NAME_COL,
                        DataHandlerDB.CONTACT_NUMBER_COL,
                        DataHandlerDB.CONTACT_DURATION_COL,
                        DataHandlerDB.CONTACT_DATE_COL},新的INT [] {
                        R.id.contact_name,R.id.phone_number,R.id.duration,
                        R.id.date});        listview.setAdapter(适配器);
    }
}


这是一个扩展的ActivityGroup活动的呼吁是这样的:

  tabHost.addTab(tabHost.newTabSpec(三化)。setIndicator(过滤器选项
                res.getDrawable(R.drawable.filteroptionsiconfile))
                .setContent(新意图(这一点,FilterOptionsGroup.class)));

FilterOptionsGroup.java

 公共类FilterOptionsGroup扩展的ActivityGroup {    公共静态FilterOptionsGroup组;
    私人的ArrayList<视图>历史;    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){        super.onCreate(savedInstanceState);
        this.history =新的ArrayList<视图>();
        组=这一点;        查看查看= getLocalActivityManager()(。startActivity
                FilterOptions
                新的意图(这一点,FilterOptions.class)
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                .getDecorView();        replaceView(视图);    }    公共无效replaceView(视图v){
        //添加旧的历史
        history.add(五);
        //改变该组查看到新的视图。
        的setContentView(五);
    }}


解决方案

如果您所有的活动都封装在一个标签主机内,他们在标签那么他们是不是真的坐在堆栈中的所有主机。他们正坐在这就是标签主机屏幕和后退按钮将下降到previous应用前景视图中。

Im having this error with backbutton on my activities. All activities has this problem. When I press Back Button it goes to home screen, not to last activity in stack. I've putted a Log message but in some activities it doesnt print it on LogCat, in this activity posted here ir prints the log. But it looks like for some activities its no goin inside the method.

There are three tabs in my application, one of them extends ActivityGroup instead of Acitivty. But I dont think its the problem, Ive removed this tab and it keeps happening.

So my question is, how do I solve it, how do I make it go to last activity instead going to home screen?

In fact it goes to the last screen where it was called. If I call it on the home screen it goes to this, if I call it on the main screen, where I put shortcuts and widgets it goes to this screen. And for what I've read in docs, it should go to the last in history stack, which means that this screen is on the stack, but no my activities. Right?

Ive tried to put this but doesnt work for any activity. It keeps goint to homescreen. I dont know what can it be.

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
                finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

I also tried with onBackPressed() method, but nothing. And also, instead of calling finish I tried with a new intent and calling the some activity explicity, but nothing too.

I cant put all my activities here because are a lot.
But Here is one, and maybe if something works with this I can implement on others. Thanks.

public class MyActivity extends Activity {

    private ListView listview;
    private ImageView imgView;
    private Resources res;
    private Drawable transition;
    private SimpleCursorAdapter adapter;
    private DataHandlerDB handler;
    private SQLiteDatabase db;
    private OpenHelper helper;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);          
        helper = new OpenHelper(this);
        db = helper.getWritableDatabase();
        setBasicContent();

    }

    @Override
    public void onStart() {

        super.onStart();
        helper = new OpenHelper(this);
        db = helper.getWritableDatabase();
        setBasicContent();

    }

    @Override
    public void onDestroy() {

        super.onDestroy();
        DataHandlerDB.selectTopCalls(this).close();
        db.close();
        helper.close();

    }

    @Override
    public void onPause() {

        super.onPause();

    }

    @Override
    public void onStop() {

        super.onStop();
        DataHandlerDB.selectTopCalls(this).close();
        db.close();
        helper.close();

    }

    @Override
    protected void onResume() {

        super.onResume();
        setBasicContent();

    }


    public void setBasicContent() {

        listview = (ListView) findViewById(R.id.list_view);

        Cursor c = DataHandlerDB.selectTopCalls(this);      

        c.moveToFirst();

        startManagingCursor(c);     

        adapter = new SimpleCursorAdapter(this, R.layout.list_item, c,
                new String[] { DataHandlerDB.CONTACT_NAME_COL,
                        DataHandlerDB.CONTACT_NUMBER_COL,
                        DataHandlerDB.CONTACT_DURATION_COL,
                        DataHandlerDB.CONTACT_DATE_COL }, new int[] {
                        R.id.contact_name, R.id.phone_number, R.id.duration,
                        R.id.date });       

        listview.setAdapter(adapter);
    }
}


Here is the activity that extends ActivityGroup its called like this:

tabHost.addTab(tabHost.newTabSpec("three").setIndicator("Filter Options", 
                res.getDrawable(R.drawable.filteroptionsiconfile))
                .setContent(new Intent(this, FilterOptionsGroup.class)));

FilterOptionsGroup.java

public class FilterOptionsGroup extends ActivityGroup {

    public static FilterOptionsGroup group;
    private ArrayList<View> history;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        this.history = new ArrayList<View>();
        group = this;

        View view = getLocalActivityManager().startActivity(
                "FilterOptions",
                new Intent(this, FilterOptions.class)
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                .getDecorView();

        replaceView(view);

    }

    public void replaceView(View v) {
        // Adds the old one to history
        history.add(v);         
        // Changes this Groups View to the new View.
        setContentView(v);
    }

}

解决方案

If all of your activities are encapsulated within a tab host and they are all hosted in tabs then they are not really sitting in the stack. They are sitting within the foreground view which is the tab host screen and the back button will drop you to the previous app.

这篇关于后退按钮不调用历史堆栈最后一项活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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