开发者

My app isn't closing correctly and I'm not sure why

开发者 https://www.devze.com 2023-04-08 11:09 出处:网络
First off, I\'m using the Action Bar. When I go back to my Main class after pressing the Home option, then press the Back button, my app won\'t close like it should. Instead, it tries to open the acti

First off, I'm using the Action Bar. When I go back to my Main class after pressing the Home option, then press the Back button, my app won't close like it should. Instead, it tries to open the activity it left from, but since I'm calling finish(), it just animates like it's switching activities and then shows my Main class. After this, I can press the Back button and properly close the app. If I don't press the Home option and use the Back button from my second activity, everything works like it should.

Intent leading back to my Main class.

@Override
public boolean onOptionsItemSelect开发者_JS百科ed(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        Intent intent = new Intent(First.this, Second.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(intent);
        finish();

    }
    return super.onOptionsItemSelected(item);
}


Try using intent.addflags(flags) not using intent.setflags(flags)...!!!!!

0

精彩评论

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

关注公众号