Starting one activity brings all the other activities in the same process to front?

by krox » Wed, 21 Apr 2010 08:44:31 GMT

Sponsored Links

I have an application consisting of two activities (call them Display
and Preferences) and one service which listens for incoming
phonecalls. When it detects one it launches the Display-activity with
a delay of 3sec in order to let the PhoneApp launch first. The Display-
activity is transparent so the user can still use the PhoneApp as
normal (ie answering the call) even though my Display-activity is "on
top". So far so good :-)

Now to my problem. Lets say that the Preferences-activity is active
when there is an incoming call. The PhoneApp is launched on top of the
Preferences-activity as expected. However when the Display-activity is
launched the Preferences-activity pops up as well, hiding the
PhoneApp. My question is if it is possible to work around this in some
way? Since I do not want my Preferences-activity to block the PhoneApp
and hence making it impossible for the user to answer the incoming
phone call.

Kind regards,


Starting one activity brings all the other activities in the same process to front?

by Dianne Hackborn » Wed, 21 Apr 2010 09:24:41 GMT

 This is due to "task affinities."  By default all activities in an .apk have
the same task affinity, so that when one is launched it is associated with
any current task started via any other activities in the app.

If you publish multiple top-level activities in your app, you will probably
want to give them different task affinities so the system does not try to
treat them as part of the same logical flow.  This is accomplished with the
android:taskAffinity attribute in the manifest, as described here: #afftask

< #afftask>And
here: #aff

Another place where it is useful to set the taskAffinity is for an activity
that is launched from a notification, so that it will be launched separately
from the main application and thus allow the user to press back to return to
whatever they were doing instead of having to go back through whatever is on
your main task's stack.  In this case you would set android:taskAffinity="",
saying that activity has no affinity to other activities.


Sponsored Links

Starting one activity brings all the other activities in the same process to front?

by krox » Wed, 21 Apr 2010 10:29:30 GMT


> >

Other Threads

1. scroll

How do you catch a scroll event ?
like a mouse-drag in other window frameworks

I've being looking into this for hours and cannot figure it out.  I got
onTouchEvent to work, but it is not good enought to do scrolling with it
I am inheriting View class to create a custom control.

thanks for any help


2. read XML from httpConnection

Code I am using, working just fine:

------------- snip --------------
                    SAXParserFactory parserFactory = 
                    SAXParser parser = parserFactory.newSAXParser();
                    MyParseHandler handler = new MyParseHandler();
                    URL url = new URL("http://" + hostname + request );
                    URLConnection connection = url.openConnection();
                    HttpURLConnection httpConnection =
                    int responseCode = httpConnection.getResponseCode();
                    if (responseCode == HttpURLConnection.HTTP_OK) {
                        InputStream in = httpConnection.getInputStream();
                        try {
                            parser.parse(in, handler);
                        } catch(org.xml.sax.SAXException e) {
                                Log.v("Parse exception", "MyParseHandler parse 
exception: "
+ e.getMessage());
                                errorMsg = "routeConfig parse exception: " +
------------- snip --------------

On a functional level this does not look that much different from
yours, so the problem must be some place else. Perhaps having to log
in throws you off.


3. Conversion help !!

4. using Apache XmlBeans in an Android application

5. read XML from httpConnection

6. external hardware in ANDROID

7. Android XML documentation?