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