关于两个activity传值问题(不是新生成的两个activity) intent getdata

最新,开发项目就遇到这个问题。为了保持两个Activity原来的状态,而又须要传值,解决这个问题仍是很简单:html

      为了避免让Activity 新生成通常要加intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);ide

    它表示你跳转的activity若是第一次生成了之后就不在生成了。因此,根据activity的生命周期(这个大家能够本身去跟断点),每次进入activity执行onResume方法,spa

@Override
    protected void onResume() {
  Log.i("onResume1111111111111111", "onResume");
  Bundle b = getIntent().getExtras();
  labelcontent = b.getString("addLabel");
  labelNumber = b.getInt("num");
  isAgainLoad = b.getBoolean("isAgainLoad");
  super.onResume();
 };.net

 

而后重写onNewIntent方法,这个方法就是在不onDestroy activity的同时,可以传值orm

@Override
 protected void onNewIntent(Intent intent) {
 
  super.onNewIntent(intent);
  setIntent(intent); 
  
 }htm

////////////////////////////////////////////////////////////////////////////////////////////
blog

onCreate是用来建立一个Activity也就是建立一个窗体,但一个Activty处于任务栈的顶端,若再次调用startActivity去创 建它,则不会再次建立。若你想利用已有的Acivity去处理别的Intent时,你就能够利用onNewIntent来处理。在onNewIntent 里面就会得到新的Intent.生命周期

[html] view plaincopyci

  1. @Override  开发

  2.         protected void onNewIntent(Intent intent) {  

  3.                 // TODO Auto-generated method stub  

  4.                 super.onNewIntent(intent);  

  5.                   

  6.         }  

若是IntentActivity处于任务栈的顶端,也就是说以前打开过的Activity,如今处于onPauseonStop 状态的话其余应用再发送Intent的话,执行顺序为:onNewIntentonRestartonStartonResume

相关文章
相关标签/搜索