Hi Dianne,

Thanks for the reply. I want to let you know the exact dilemma I am in.

My application is a client based financial app and compulsorily it needs to
validate the user token from the server every time it comes to foreground.
This is a security mandate.

Are you aware of any call back( ( Activity) or (Context ) level)/or
any workaround  that we can use when the App is brought to foreground from
the Recent Apps. Usually the user of my app would be in some secondary
activity launched by the root activity.

I works fine in all the App launch scenarios except the Recent App workflow
where any of my Secondary activity has *no way* to know that it has been
brought to the foreground from the Recent Apps.

If you are aware of some good practice for this kind of situation,
any suggestion or advice would be greatly appreciated.

Thanks
AndUzer

On Sat, Apr 30, 2011 at 7:28 PM, Dianne Hackborn <hack...@android.com>wrote:

> Sorry, this information is not available if your task has has multiple
> activities in it.
> On Apr 30, 2011 3:18 AM, "Manohar Mahapatra" <androidu...@gmail.com>
> wrote:
> > Hi Dianne,
> >
> > I was aware of all these flags. My app has a requirement to know when my
> > root / secondary activities are brought to focus by long clicking Home
> > (Recent Apps). So I started using
> > FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY<
> http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
> >
>
> > in
> > my code but saw that it was never set in getFlags(). Then I did more
> > investigation and I found all these observation below.
> >
> > Can you let me know how to know for any activity(other than root
> activity) *on
> > top of App task* to know that it has been launched by long clicking Home
> > (Recent Apps) . As per my observation, getFlags() returns 0 for any
> > secondary activity
> > (i.e other than the root activity) that is launched by root activity.
> >
> > thanks for your inputs and time
> > AndUzer
> >
> > On Sat, Apr 30, 2011 at 12:32 PM, Dianne Hackborn <hack...@android.com
> >wrote:
> >
> >> Why do you care? You are looking at log statements. The log from the
> >> activity manager happens to be the Intent printed at some point in its
> >> processing. There is nothing defined in the API that some log print in
> the
> >> system is going to have the same Intent flags values as what is handed
> to
> >> the application.
> >>
> >> The activity manager is printing the intent that is handed to it when
> the
> >> request to start the activity happens. It will add in flags that should
> be
> >> set for the launch at that point as defined by the API.
> >>
> >> Did you even look at what these flags are?
> >>
> >> 0x10000000:
> >>
> http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK
> >>
> >> 0x00100000:
> >>
> >>
> http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
> >>
> >> 0x00200000:
> >>
> >>
> http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
> >>
> >> And for the one where you say there are no flags, yes, there are no flag
> >> bits set so to save space nothing is printed about the flag.
> >>
> >> This all seems to be working perfectly fine to me,
> >>
> >> On Sat, Apr 30, 2011 at 12:10 AM, Manohar Mahapatra <
> androidu...@gmail.com
> >> > wrote:
> >>
> >>> Hi,
> >>>
> >>>
> >>>
> >>> I am seeing some issues in the way the following API( *getFlags()*) of
> >>> the Intent class works . I see that the Activity Manager starts a
> Activity
> >>> with some value of flag set in the Intent but when I print the Intent
> object
> >>> in the root Activity ,
> >>>
> >>> the flag value in the Intent object is not same as what Activity
> Manager
> >>> launched the intent with for some scenarios. Second issue Any other
> Activity
> >>> launched by the root activity has no info of the flag in the intent
> >>>
> >>>
> >>>
> >>> "int getFlags<
> http://developer.android.com/reference/android/content/Intent.html#getFlags%28%29
> >()
>
> >>>
> >>>
> >>> Retrieve any special flags associated with this intent."
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> In my use case , I have an Application which has two activities, the
> >>> Android Manifest file looks something like this
> >>>
> >>>
> >>>
> >>> <?xml version=*"1.0"* encoding=*"utf-8"*?>
> >>>
> >>> <manifest xmlns:android=*"http://schemas.android.com/apk/res/android"*
> >>>
> >>> package=*"com.example.flag"*
> >>>
> >>> android:versionCode=*"1"*
> >>>
> >>> android:versionName=*"1.0"*>
> >>>
> >>> <application android:icon=*"@drawable/icon"* android:label=*
> >>> "@string/app_name"*>
> >>>
> >>> <activity android:name=*".MainActivity"*
> >>>
> >>> android:label=*"@string/app_name"*>
> >>>
> >>> <intent-filter>
> >>>
> >>> <action android:name=*"android.intent.action.MAIN"* />
> >>>
> >>> <category android:name=*
> >>> "android.intent.category.LAUNCHER"* />
> >>>
> >>> </intent-filter>
> >>>
> >>> </activity>
> >>>
> >>>
> >>>
> >>> <activity android:name=*".SecondActivity"*
> >>>
> >>> android:label=*"@string/app_name1"*>
> >>>
> >>> </activity>
> >>>
> >>> </application>
> >>>
> >>> </manifest>
> >>>
> >>>
> >>>
> >>> The code for the “MainActivity” is as follows
> >>>
> >>>
> >>>
> >>> *package* com.example.flag;
> >>>
> >>> *import* android.app.Activity;
> >>>
> >>> *import* android.content.Intent;
> >>>
> >>> *import* android.os.Bundle;
> >>>
> >>> *import* android.util.Log;
> >>>
> >>> *import* android.view.View;
> >>>
> >>> *import* android.view.View.OnClickListener;
> >>>
> >>> *import* android.widget.Button;
> >>>
> >>>
> >>>
> >>> *public* *class* MainActivity *extends* Activity {
> >>>
> >>> /** Called when the activity is first created. */
> >>>
> >>> @Override
> >>>
> >>> *public* *void* onCreate(Bundle savedInstanceState) {
> >>>
> >>> *super*.onCreate(savedInstanceState);
> >>>
> >>> setContentView(R.layout.*main*);
> >>>
> >>>
> >>>
> >>> Button b = (Button) findViewById(R.id.*button1*);
> >>>
> >>> b.setOnClickListener(*new* OnClickListener() {
> >>>
> >>> *public* *void* onClick(View v) {
> >>>
> >>> startActivity(*new* Intent(MainActivity.*this*
> >>> ,SecondActivity.*class*));
> >>>
> >>> }
> >>>
> >>> });
> >>>
> >>> }
> >>>
> >>>
> >>>
> >>> /* (non-*Javadoc*)
> >>>
> >>> * @see android.app.Activity#onResume()
> >>>
> >>> */
> >>>
> >>> @Override
> >>>
> >>> *protected* *void* onResume() {
> >>>
> >>> *super*.onResume();
> >>>
> >>> Log.*d*("MainActivity", "MainActivity
> >>> getIntent().toString()::" +getIntent().toString());
> >>>
> >>> }
> >>>
> >>> }
> >>>
> >>>
> >>>
> >>> The code for the “SecondActivity” is as follows
> >>>
> >>>
> >>>
> >>> *package* com.example.flag;
> >>>
> >>>
> >>>
> >>> *import* android.app.Activity;
> >>>
> >>> *import* android.graphics.Color;
> >>>
> >>> *import* android.os.Bundle;
> >>>
> >>> *import* android.util.Log;
> >>>
> >>> *import* android.widget.TextView;
> >>>
> >>>
> >>>
> >>> *public* *class* SecondActivity *extends* Activity {
> >>>
> >>> /** Called when the activity is first created. */
> >>>
> >>> @Override
> >>>
> >>> *public* *void* onCreate(Bundle savedInstanceState) {
> >>>
> >>> *super*.onCreate(savedInstanceState);
> >>>
> >>>
> >>>
> >>> TextView tv= *new* TextView(*this*);
> >>>
> >>> tv.setText("Second Activity");
> >>>
> >>> tv.setBackgroundColor(Color.*WHITE*);
> >>>
> >>> setContentView(tv);
> >>>
> >>> }
> >>>
> >>>
> >>>
> >>> /* (non-*Javadoc*)
> >>>
> >>> * @see android.app.Activity#onResume()
> >>>
> >>> */
> >>>
> >>> @Override
> >>>
> >>> *protected* *void* onResume() {
> >>>
> >>> *super*.onResume();
> >>>
> >>> Log.*d*("SecondActivity", "MainActivity SecondActivity
> "+getIntent().toString());
> >>>
> >>> }
> >>>
> >>>
> >>>
> >>> }
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> First time launch , both the flags in ActivityManager and my
> >>> app(MainActivity) are same
> >>>
> >>> 04-30 03:14:05.132: INFO/ActivityManager(71): Starting activity: Intent
> {
> >>> act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] *
> >>> flg=0x10000000* cmp=com.example.flag/.MainActivity }
> >>>
> >>> 04-30 03:14:05.372: INFO/ActivityManager(71): Start proc
> com.example.flag
> >>> for activity com.example.flag/.MainActivity: pid=235 uid=10032
> gids={1015}
> >>>
> >>> 04-30 03:14:10.722: DEBUG/MainActivity(235): MainActivity
> getIntent().toString()::Intent
> >>> { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]
> *
> >>> flg=0x10000000* cmp=com.example.flag/.MainActivity }
> >>>
> >>> 04-30 03:14:11.132: INFO/ActivityManager(71): Displayed activity
> >>> com.example.flag/.MainActivity: 5970 ms (total 5970 ms)
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> Then I press Home button , then I do a Long press Home to launch
> >>> MainActivity from the Recent Apps, I get this log and I see now *they
> are
> >>> not same.*
> >>>
> >>> 04-30 03:15:03.353: INFO/ActivityManager(71): Starting activity: Intent
> {
> >>> act=android.intent.action.MAIN cat=[android.intent.category.HOME]
> >>> flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher
> }
> >>>
> >>> 04-30 03:15:15.562: INFO/ActivityManager(71): Starting activity: Intent
> {
> >>> act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] *
> >>> flg=0x10100000* cmp=com.example.flag/.MainActivity }
> >>>
> >>> 04-30 03:15:15.652: DEBUG/MainActivity(235): MainActivity
> getIntent().toString()::Intent
> >>> { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]
> *
> >>> flg=0x10000000* cmp=com.example.flag/.MainActivity }
> >>>
> >>>
> >>>
> >>> Then I Press back on the MainActivity , bringing me to Android Home and
> >>> from the Home Page Icon List, again I launch the Main Activity, this
> time
> >>> the flags are same again
> >>>
> >>> 04-30 03:16:10.412: INFO/ActivityManager(71): Starting activity: Intent
> {
> >>> act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] *
> >>> flg=0x10200000* cmp=com.example.flag/.MainActivity }
> >>>
> >>> 04-30 03:16:10.722: DEBUG/MainActivity(235): MainActivity
> getIntent().toString()::Intent
> >>> { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]
> *
> >>> flg=0x10200000* cmp=com.example.flag/.MainActivity }
> >>>
> >>> 04-30 03:16:10.982: INFO/ActivityManager(71): Displayed activity
> >>> com.example.flag/.MainActivity: 465 ms (total 465 ms)
> >>>
> >>>
> >>>
> >>> Then I press Home button , then I do a Long press Home to launch
> >>> MainActivity from the Recent Apps, I get this log and I see now *they
> are
> >>> not same.*
> >>>
> >>> 04-30 03:16:21.883: INFO/ActivityManager(71): Starting activity: Intent
> {
> >>> act=android.intent.action.MAIN cat=[android.intent.category.HOME]
> >>> flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher
> }
> >>>
> >>> 04-30 03:16:30.293: INFO/ActivityManager(71): Starting activity: Intent
> {
> >>> act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] *
> >>> flg=0x10100000* cmp=com.example.flag/.MainActivity }
> >>>
> >>> 04-30 03:16:30.382: DEBUG/MainActivity(235): MainActivity
> getIntent().toString()::Intent
> >>> { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]
> *
> >>> flg=0x10200000* cmp=com.example.flag/.MainActivity }
> >>>
> >>>
> >>>
> >>> Then I launch SecondActivity from the Main Activity
> >>>
> >>> 04-30 03:16:49.132: INFO/ActivityManager(71): Starting activity: Intent
> {
> >>> cmp=com.example.flag/.SecondActivity }
> >>>
> >>> 04-30 03:16:49.233: DEBUG/SecondActivity(235): MainActivity
> SecondActivity
> >>> Intent { cmp=com.example.flag/.SecondActivity }
> >>>
> >>> 04-30 03:16:49.542: INFO/ActivityManager(71): Displayed activity
> >>> com.example.flag/.SecondActivity: 338 ms (total 338 ms)
> >>>
> >>>
> >>>
> >>> I press Home button, I do a Long press Home to launch
> >>> MainActivity(MainActivity is first activity of this app task,Second
> Activity
> >>> being on top of MainActivity) from the Recent Apps, I get this log and
> I
> >>> don’t get any Flags from the Second Activity
> >>>
> >>> 04-30 03:16:56.833: INFO/ActivityManager(71): Starting activity: Intent
> {
> >>> act=android.intent.action.MAIN cat=[android.intent.category.HOME]
> >>> flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher
> }
> >>>
> >>> 04-30 03:17:05.962: INFO/ActivityManager(71): Starting activity: Intent
> {
> >>> act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]
> >>> flg=0x10100000 cmp=com.example.flag/.MainActivity }
> >>>
> >>> 04-30 03:17:06.022: DEBUG/SecondActivity(235): MainActivity
> SecondActivity
> >>> Intent { cmp=com.example.flag/.SecondActivity } *// No flag info here*
> >>>
> >>> *
> >>> *
> >>>
> >>> *
> >>> *
> >>>
> >>> I request anyone to tell me if there is some gap in my understanding or
> if
> >>> I did not use the components in proper way
> >>>
> >>>
> >>> thanks in advance
> >>>
> >>> AndUzer
> >>>
> >>> --
> >>> You received this message because you are subscribed to the Google
> Groups
> >>> "android-platform" group.
> >>> To post to this group, send email to android-platf...@googlegroups.com
> .
> >>> To unsubscribe from this group, send email to
> >>> android-platform+unsubscr...@googlegroups.com.
> >>> For more options, visit this group at
> >>> http://groups.google.com/group/android-platform?hl=en.
> >>>
> >>
> >>
> >>
> >> --
> >> Dianne Hackborn
> >> Android framework engineer
> >> hack...@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-platform" group.
> >> To post to this group, send email to android-platf...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> android-platform+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/android-platform?hl=en.
> >>
> >
> > --
> > 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+unsubscr...@googlegroups.com
>
> > For more options, visit this group at
> > http://groups.google.com/group/android-developers?hl=en
>
> --
> You received this message because you are subscribed to the Google Groups
> "android-platform" group.
> To post to this group, send email to android-platf...@googlegroups.com.
> To unsubscribe from this group, send email to
> android-platform+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/android-platform?hl=en.
>

-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to