/////本来是做的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了,,,,,

测试文件,

布局1:

<?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>

布局2:

<?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>

对应的activity1

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"));
    }
}

activity2

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++);
    }
}

多个activity跳转保留内存使用intent传递数据问题_新手的更多相关文章

  1. Android Activity传递数据使用getIntent()接收不到,揭秘Intent传递数据与Activity启动模式singleTask的关系。

    activity通过intent传递数据的时候,如果activity未启动,那么在这个刚启动的activity里通过getIntent()会获取到这个intent的数据.. 如果要启动的activit ...

  2. Android Intent传递数据

    刚开始看郭大神的<>,实现以下里面的一些例子.Intent传递数据. 我们利用显示的方式进行Intent的启动. 1.启动intent并输入数据. Intent intent=new In ...

  3. 【转】Android 之最新最全的Intent传递数据方法

    原文地址:https://www.jianshu.com/p/1169dba99261 intent传递数据 为什么要和intent单独拿出来讲,因为Intent传递数据也是非常重要的 一.简单的传递 ...

  4. Intent传递数据从一个Activity到另一个Activity

    MainActivity package com.test.intentdemo; import android.app.Activity; import android.content.Intent ...

  5. Android学习之基础知识四-Activity活动4讲(Intent传递数据)

    Intent除了可以开启一个活动,还能在启动活动的时候传递数据,此时Intent相当于一个保存数据的库,我们先把数据保存在Intent中,然后再根据各个activity的需要从其中取出数据.  一.使 ...

  6. Android 消息广播Intent传递数据

    1.创建布局文件activity_broadcast.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk ...

  7. Intent传递数据

    方式比较多,先看看代码,一会儿再总结. activity_main.xml <RelativeLayout xmlns:android="http://schemas.android. ...

  8. Android 开发中使用Intent传递数据的方法

    Activity之间通过Intent传递值,支持基本数据类型和String对象及 它们的数组对象byte.byte[].char.char[].boolean.boolean[].short.shor ...

  9. Android学习之Intent传递数据

    Intent在Activity中的作用主要是有两个: 1.启动目标Activity 2.传递数据 Intent在传递数据时分两种情况:向下一个Activity传递数据和从下一个Activity返回数据 ...

随机推荐

  1. JSON 理解

    转自: http://blog.csdn.net/qyf_5445/article/details/8635578 (json很全面的理解) http://www.cnblogs.com/haitao ...

  2. MySQL的JOIN(四):JOIN优化实践之快速匹配

    这篇博文讲述如何优化扫描速度.我们通过MySQL的JOIN(二):JOIN原理得知了两张表的JOIN操作就是不断从驱动表中取出记录,然后查找出被驱动表中与之匹配的记录并连接.这个过程的实质就是查询操作 ...

  3. Windows10下通过anaconda安装tensorflow

    博主经历了很多的坎坷磨难才找到一个比较好的在win10下安装TensorFlow的方法: 首先需要说明的是如果你想通过Anaconda来安装tensorflow的话,首先要确认你的python的版本是 ...

  4. 201521123013 《Java程序设计》第7周学习总结

    1. 本章学习总结 2. 书面作业 Q1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 public boolean contains(Object o) { r ...

  5. 201521123038 《Java程序设计》 第四周学习总结

    201521123038 <Java程序设计> 第四周学习总结 1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. 1.通过 ins ...

  6. 201521123020 《Java程序设计》第9周学习总结

    1.本周学习总结 2. 书面作业 1.常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己以前编写的代码中经常出现什么异常.需要捕获吗(为什么)?应如何避免? 答:数组越界:不需要 ...

  7. iOS - 内购总结

        如果有人以后要在做内购这一块.希望可以好好的阅读这篇文章,虽然不是字字珠玑.但是也是本人亲人趟过了无数的坑,希望可以对大家有所帮助!  下面是在研究工程中遇到的问题(iOS 内购的流程如下 1 ...

  8. Hibernate table schema 的设置与应用

    hibernate在实现实体映射时,DB无需强行指定.部署时会较对DB户名和密码,根据用户名以访问的表完成实体映射.如果一个帐号可以访问一个数据库的下多个表,以oracle为例用户user1下面有表t ...

  9. Oracle存储过程经典入门

    ok基本就这些介绍

  10. 深入理解分布式调度框架TBSchedule及源码分析

    简介 由于最近工作比较忙,前前后后花了两个月的时间把TBSchedule的源码翻了个底朝天.关于TBSchedule的使用,网上也有很多参考资料,这里不做过多的阐述.本文着重介绍TBSchedule的 ...