【问题标题】:How to have an android start fresh with every restart每次重启时如何让android重新开始
【发布时间】:2014-05-26 23:05:21
【问题描述】:

我的应用中有大量活动,我在使用意图之间进行转换。我希望应用每次启动时都好像它已从后台清除一样。我在任何地方都找不到如何做到这一点。谢谢。

【问题讨论】:

  • “我希望应用程序每次都像从后台清除一样启动”是什么意思?
  • 你的意思是你想让你的应用每次都从同一个主要活动开始?
  • 我的意思是app总是从同一个activity启动,不能放到后台再在app中间重新进入。

标签: android android-activity kill


【解决方案1】:

试试这个

Intent intent = new Intent(ProfileActivity.this,
LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
startActivity(intent);

【讨论】:

    【解决方案2】:

    我想您想在清除活动堆栈的情况下启动应用程序。

    Intent intent_activity=new Intent(MainActivity.this, Activity2.class);
                intent_activity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent_activity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent_activity);
    

    使用flags让你shure栈被清空并声明activity生命周期的状态

      @Override
    protected void onCreate() {
        super.onCreate();
    }
    
     @Override
    protected void onStart() {
        super.onStart();
    }
    
    @Override
    protected void onStop() {
        super.onStop();
    }
    
    @Override
    protected void onPause() {
        super.onPause();
    }
    
    @Override
    protected void onResume() {
        super.onResume();
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-13
      • 1970-01-01
      • 2021-08-04
      • 2011-07-19
      • 2011-05-12
      • 2021-10-04
      • 1970-01-01
      相关资源
      最近更新 更多