Sunil
Sunil

Reputation: 864

Intent flags and launchMode

I have a service S which gets started as soon as the boot is completed. I have an application with one Activity which binds to the service S when the app is launched.

Now I have registered a broadcast receiver for certain event so that if the event occurs I should launch the same Activity. I don't want another instance of the same Activity to be created, I want to reuse the Activity but onCreate() or onRestart() method of the Activity should be called.

How can I achieve this?

Upvotes: 0

Views: 391

Answers (3)

dorjeduck
dorjeduck

Reputation: 7794

If you want to understand intents go for

http://blog.akquinet.de/2010/04/15/android-activites-and-tasks-series-intent-flags/

its very clear and the demo app coming along with it really helpful.

Upvotes: 0

Barrie Galitzky
Barrie Galitzky

Reputation: 1156

I'm not 100% positive of your question, but here we go. You could try using a static method in your mainactivity and call it from your service.

In your main activity:

  @Override
public void onCreate() {
    super.onCreate();
    superAwesomeMethod();

public static void superAwesomeMethod() {
    //stuff you want called on onCreate

then in your Service:

//event listener capture
YourActivityName.superAwesomeMethod();

Upvotes: 1

midhunhk
midhunhk

Reputation: 5554

Try your AndroidManifest.xml with this

<activity android:launchMode="singleTop">

for your main activity

Upvotes: 0

Related Questions