Search code examples
javaandroidprocess

How to Log.d messages from another process of the same app?


I need to make a Service that must run in a separate process so that it still run when the MainActivity is closed. And I use android:process=":myprocess" in manifest for that. If I don't insert this in the project manifest and run the app, I can see the massages from the service, but when I start it in another process the messages from Log.d are no longer shown. Is there a way to make it work ?


Solution

  • Briefcase will only show logs from your app's main process. To see the other process, you could use Android Studio's Logcat view, or the adb logcat command.

    However, for your use case I don't think you actually need a separate process. By default, all activities and services will be run in the main process, and that process will continue to exist for as long as at least one of its components is active.

    Android's decision about when to shut down a service is determined by other factors which you've already discovered in your other question. I don't think putting it in a separate process will make much difference to that.

    Also, adding a second process is a significant complication which is probably more trouble than it's worth. For example, the two processes won't be able to communicate with each other by simple method calls, and will have to use Intents, sockets or bound Service interfaces instead.