0

Hi hopefully this will be an easy one. I need to implement the classic "call app from another app" in Android, which has tons of suggestions on Internet and SO.

I tried:

Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setComponent(new ComponentName("a.b.c","a.b.c.classname"));
        getContext().startActivity(intent);

and

    Intent intent = getContext().getPackageManager()
            .getLaunchIntentForPackage(app);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    getContext().startActivity(intent);

they both work and correctly spawn a new activity from my app, especially if the app was not running.

When the app is already running I get problems because I see that the methods above call the onCreate()/onRestart() methods rather than onResume()/onRestart() as in a "manual" selection of the app (i.e. touching the icon form desktop, that works fine).

The problem in calling onCreate() again is that I set up a TCP server here, which obviously cannot be re-created on the same port.

I could in principle check if the app is running and hijack the onCreate() to onResume() method but that's a bit of a bad hack.

Any ideas to do this "right"?

cheers

Lele
  • 281
  • 3
  • 13

1 Answers1

0

I think you can pass parameter when you start another application.
You can see this as a reference pass parameter when start other application.
When the OnCreate function is called, it check the parameter and start TCP server if needed.

Community
  • 1
  • 1
binhgreat
  • 982
  • 8
  • 13
  • thanks, after some cleaning and re-installing now it seems I no longer have issues with the server. If I get the same problem in the future I'll try your suggestion. cheers – Lele Mar 17 '12 at 09:49