Display new Activity on top of previous Activity

problem:

SecondActivity overlay on FirstActivity, FirstActivity gets dimmed, SecondActivity gets displayed on top of FirstActivity.

possible solution:

1. Dialog

  • set SecondActivity up as a dialog — which will dim the background
  • If you want to do this using an Activity instead of a Dialog, you can do this by setting the activity’s theme to android:theme="@android:style/Theme.Dialog" in the manifest – this will make the activity appear like a dialog (floating on top of whatever was underneath it).

2. Fragments can be used to fill a part of the screen, while doing something else entirely in a different one.

e.g. A app containing a main content area and a music player. The music player stays in place while the main content changes.

Android User Interface Design: Working With Fragments

一个Activity 可以启动另一个Activity,即使这个Activity是定义在别一个应用程序里的,比如说,想要给用户展示一个地图的信息,现在已经有一个Activity可以做这件事情,那么现在你的Activity需要做的就是将请求信息放进一个Intent对象里,并且将这个Intent对象传递给startActivity(),那么地图就可显示出来了,但用户按下Back键之后,你的Activity又重新出现在屏幕上。

Android将你的Activity和借用的那个Activity被放进一个Task中以维持用户的体验。当一个Activity启动另一个Activity时,新启动的Activity被压进栈中,成为正在运行的Activity。旧的Activity仍然在栈中。当用户按下BACK键之后,正在运行的Activity弹出栈,旧的Activity恢复成为运行的Activity

栈中包含对象,因此如果一个任务中开启了同一个Activity子类的的多个对象——例如,多个地图浏览器——则栈对每一个实例都有一个单独的入口。栈中的Activity不会被重新排序,只会被、弹出。

Task是一组Activity实例组成的栈,不是在manifest文件里的某个类或元素,所以无法设定一个Task的属性而不管它的Activity,一个Task的所有属性值是在底部的Activity里设置的,这就需要用于Affinity。

Affinity

affinity用于指定activity所属的task。默认状态下,一个app中的所有activity都有相同的affinity,所以它们会运行在同一个task。而通过<activity>的taskAffinity属性可以指定affinity。

taskAffinity要用<manifest>中定义的唯一包名来取值,系统通过包名定位到app的默认task。

taskAffinity在以下2种情况中发生作用:

  • 使用FLAG_ACTIVITY_NEW_TASK启动一个activity。如果该activity指定了taskAffinity,系统会将activity实例置于指定的task中。 注意的是,此情况下如果用户点击HOME键,必须要确定有办法能回到那个task中!(例如task所属的app在launcher有自己icon)
  • activity 设置了 allowTaskReparenting = “true”。 当activity所在的task被移到前台时,该activity会被移动到affinity指定的task中。
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: