¿Cómo cambiar a otra aplicación SIN llamar a onCreate (si está abierta)?

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.

Lo intenté:

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


    Intent intent = getContext().getPackageManager()

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"?


preguntado el 10 de marzo de 12 a las 13:03

1 Respuestas

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.

contestado el 23 de mayo de 17 a las 12:05

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

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.