return back to previous activity [android]

Do not finish the first activity when calling the second one
要在第一个activity向第二个activity跳转的时候将第一个activity finish(),这样在第二个activity返回第一个activity时,就会执行第一个activity的onCreate()方法。

一:如果直接返回上一个界面保留原界面的状态,只需要将当前的activity终止即可

代码:shop.this.finish();

二:进入一个全新的界面,并可带参数,用Intent

代码:
Intent i= this.getIntent();
Bundle bl = new Bundle();
i.setClass(当前的Activity.this,目标Activity.class);
bl.putString("参数名",“参数值”);
i.putExtras(bl);
startActivityForResult(i, 0);

三:当前页面与前页面的result问题

activity.this.setResult(1); //其中1为标志位
前一个activity中的onActivityForResult中可进行设置
activity.this.finish();

4. 将每个activity的属性中增加 android:launchMode=”singleInstance”

在点击back键启动另一个Activity的时候新建了一个Task,将要返回的Activity放置在这个新建的Task中,而之前的那个Activity是在它自己的Task中,单击back的时候只是把它的Task弹开了,并没有将它本身弹出栈,所以可以实现楼主所描述的功能.

出处:http://blog.duteba.com/technology/article/18.htm
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

生活在西班牙

自己动手丰衣足食

BlueAsteroid

Just another WordPress.com site

Jing's Blog

Just another WordPress.com site

Start from here......

我的心情魔方

天才遠私廚

希望能做一個分享各種資訊的好地方

语义噪声

西瓜大丸子汤的博客

笑对人生,傲立寰宇

Just another WordPress.com site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision

datarazzi

Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness

槑烎

1,2,∞

Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: