/////本来是做的activity跳转,普通那种,但是会在调回来会销毁原来的,重新调用onCreate方法,

后来参考【http://blog.csdn.net/qq_26918031/article/details/52749685】,给intent设置flag,,FLAG_ACTIVITY_REORDER_TO_FRONT,

状态是保留了,但bundle数据传递布料,‘本来想使用Application存储全局的,【参照http://blog.csdn.net/li12412414/article/details/51867400】

但是翻看到疯狂android讲义第三版286页,设置了intent的flag,,,,,FLAG_ACTIVITY_BROUGHT_TO_FRONT,,,

就可以在再次启动后的onStart,onResume中找到bundle了,,,,,

多个activity跳转保留内存使用intent传递数据问题_新手

测试文件,

布局1:

多个activity跳转保留内存使用intent传递数据问题_新手多个activity跳转保留内存使用intent传递数据问题_新手
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="数据展示1"
        />
    <Button
        android:id="@+id/btn_t1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="下"
        />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="aaa"
        />
    <TextView
        android:id="@+id/tv_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="show"
        />
</LinearLayout>
View Code

布局2:

多个activity跳转保留内存使用intent传递数据问题_新手多个activity跳转保留内存使用intent传递数据问题_新手
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="数据展示2"
        />
    <Button
        android:id="@+id/btn_t2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="上"
        />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="111"
        />
    <TextView
        android:id="@+id/tv_2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="show"
        />
</LinearLayout>
View Code

对应的activity1

多个activity跳转保留内存使用intent传递数据问题_新手多个activity跳转保留内存使用intent传递数据问题_新手
package com.example.administrator.no1;
//配置日志过滤【参照:http://blog.csdn.net/hyr83960944/article/details/38268395】
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;

/**
 * Created by Administrator on 2017/10/10 0010.
 */

public class TestActivityLife1 extends AppCompatActivity {
    Button button;
    TextView textView;
    int j=1;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e("zzf","oncreate"+j++);
        setContentView(R.layout.test_a1);
        button = (Button) findViewById(R.id.btn_t1);
        textView = (TextView) findViewById(R.id.tv_1);
        button.setOnClickListener(v -> {
            Intent  intent = new Intent(TestActivityLife1.this,TestActivityLife2.class);
            Bundle bundle = new Bundle();
            bundle.putString("a","123");
            intent.putExtra("bun",bundle);
            intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
            startActivity(intent);
        });
//        getApplicationContext().put
    }

    @Override
    protected void onStart() {
        super.onStart();
//        System.out.println("start"+j++);
        Log.e("zzf","start"+j+++""+getIntent().getBundleExtra("bun"));
    }

    @Override
    protected void onStop() {
        super.onStop();
//        System.out.println("stop"+j++);
        Log.e("zzf","stop"+j++);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        System.out.println("destroy"+j++);
        Log.e("zzf","destroy"+j++);
    }

    @Override
    protected void onPause() {
        super.onPause();
//        System.out.println("zzf:pause"+j++);
        Log.e("zzf","pause"+j++);
    }


    @Override
    protected void onResume() {
        super.onResume();
//        System.out.println("resume"+j++);
        Log.e("zzf","resume"+j+++""+getIntent().getBundleExtra("bun"));
        if (getIntent().getBundleExtra("bun") != null){
            Log.e("zzf","res111回馈数据suc:"+getIntent().getBundleExtra("bun").get("name"));
        }
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.e("zzf","restart"+j+++""+getIntent().getBundleExtra("bun"));
    }
}
View Code

activity2

多个activity跳转保留内存使用intent传递数据问题_新手多个activity跳转保留内存使用intent传递数据问题_新手
package com.example.administrator.no1;
///设置了FLAG_ACTIVITY_REORDER_TO_FRONT标志后,虽然保留内存,当时bundle数据传递就没用了
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;

/**
 * Created by Administrator on 2017/10/10 0010.
 */

public class TestActivityLife2 extends AppCompatActivity {
    Button button;
    TextView textView;
    Intent intent1;
    int j;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e("zzf","oncreate"+j++);
        setContentView(R.layout.test_a2);
        button = (Button) findViewById(R.id.btn_t2);
        textView = (TextView) findViewById(R.id.tv_2);
        intent1 = getIntent();
        button.setOnClickListener(v -> {
            Intent intent = new Intent(TestActivityLife2.this,TestActivityLife1.class);
            Bundle bundle = new Bundle();
            bundle.putString("name","zzf");
            intent.putExtra("bun",bundle);
            intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
            startActivity(intent);
        });
    }
    @Override
    protected void onStart() {
        super.onStart();
//        System.out.println("start"+j++);
        Log.e("zzf","start"+j++);
    }

    @Override
    protected void onStop() {
        super.onStop();
//        System.out.println("stop"+j++);
        Log.e("zzf","stop"+j++);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        System.out.println("destroy"+j++);
        Log.e("zzf","destroy"+j++);
    }

    @Override
    protected void onPause() {
        super.onPause();
//        System.out.println("zzf:pause"+j++);
        Log.e("zzf","pause"+j++);
    }


    @Override
    protected void onResume() {
        super.onResume();
//        System.out.println("resume"+j++);
        Log.e("zzf","resume"+j++);
    }
}
View Code