0

Specfically, I have an activity that can be called from the homescreen, OR can be called by selecting "OK" from a dialog pop up in another activity. What I want is for the activity to behave slightly differently (start something automatically rather than waiting for user input ) if it was selected by the pop up.

Knowing nothing else, my first instinct is to simply set a shared preference variable when they select "OK" right before calling startActivity().Then, I can have my activity always check that shared variable before doing anything.

Is this efficient, or is there some built in Android way to do this?

I've looked at:

Android - detecting application launch from home or history

And it seems like there's no way to know if it was launched from the home screen. That's fine, because in my case I care more about whether it came from the dialog box...I don't care about any other possible way a user could get to this Activity.

I'm seeing something on "startActivityForResult"....but I'm not really waiting for any result or anything, would it be applicable here? Is there some other similar method I haven't found yet?

Community
  • 1
  • 1
J.R.
  • 5,789
  • 11
  • 55
  • 78

1 Answers1

2

when you start your activity you can put an extra to your intent:

intent.putExtra(KEY_IS_DIALOG, true);

In your second activity you can then use:

getIntent().getBooleanExtra(KEY_IS_DIALOG, defaultValue); 
Maria Neumayer
  • 3,337
  • 3
  • 27
  • 44