Friday, August 24, 2012

Re: [android-developers] Using startActivity( intent ) multiple times, fails.

This is wrong in a number of ways:

    getLaunchIntentForPackage( "com.android.email" );

First, "com.android.email" is not an API.  That is the internal identifier for the current e-mail application that is part of AOSP; there is *no* guarantee that such a thing will ever exist on the device.

Second, more specific to your issue here, getLaunchIntentForPackage() returns a *launch* intent, for use in semantics like an app launcher.  What you are asking for is not an app launcher; you want to run flow as part of your own task, not launch something different.  In particular, what this Intent will do is bring the current e-mail app to the foreground *in whatever state it was last in*.  The user may have been in the middle of composing a message, viewing something, etc.  It isn't saying to bring them to the list of e-mail messages for them to import something.

One other thing, when you say startActivityForResult() is not working, this is not because of an explicit vs. implicit Intent; this is because part of what getLaunchIntentForPackage() does is set FLAG_ACTIVITY_NEW_TASK, which says to launch the Intent as a separate task from yours (bringing an existing task to the foreground etc), which is central to the semantics of this being for app launchers not in-task UI flow.

On Thu, Aug 23, 2012 at 7:16 AM, Mark Jawdoszak <eviljawdy@gmail.com> wrote:
I have an intent that starts the default Android mail client:

Intent emailIntent = this.getPackageManager().getLaunchIntentForPackage( "com.android.email" );
this.startActivity( emailIntent );

Very simple stuff, and it fires off the Email client, from an "Import from Email" button in my app.

My application is also registered with an <intent-filter> to open PDF files.
So, if I use the above Intent to open up the Email client, find an email with a PDF attachment, download it, launch it, select my application from the chooser... then everything loads great.

Now if I hit my "Import from Email" button again, the intent runs, but the Email client is never brought into the foreground.

Am I missing something when using startActivity() to (re)launch the correct app?
I have tried checking if the intent is OK by following this http://developer.android.com/training/basics/intents/sending.html#Verify but it always returns true (and that makes sense, as it can find the Application, but it's just not bringing it to the foreground).

I have also tried using startActivityForResult(), but as explained in the Android docs, this fires off a "cancel" immediately, because the Activity is not Explicit, but Implicit (thought I'd try it, just in case).

I feel like I'm missing something, a step, a call to something... or have I hit upon some strange loop that works in one case, but cannot keep looping?  Any help/pointers would be greatly appreciated!

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en



--
Dianne Hackborn
Android framework engineer
hackbod@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment