TheOathMan / Godot-Android-Live-Wallpaper

Make your Android Godot application run as a live wallpaper in the background.
MIT License
16 stars 4 forks source link

Multiple Process Problem #3

Open kplusan opened 3 weeks ago

kplusan commented 3 weeks ago

When the app runs as wallpaper or preview status, the Android system can recognize and correctly use the same process. But when I clicking on the icon on homescreen to launch the app, it will create a new process. Is there a way to keep the app always managing and running only one process?

I have achieved this before(java) when using libgdx by extending android.app.Application and define a static game Instance within it, but now I don't know kotlin(ಥ_ಥ)

TheOathMan commented 3 weeks ago

The wallpaper process is an Android Service while the app is an Android Activity, so they run in a separate processes by design. If you're trying to sync your changes from the main app to the wallpaper service app or vice versa, you can easily store your changes on a user:// path, then load these changes on _on_live_wallpaper_visibility_changed(visibility: bool) signal.

However, you can still use the same process to run the app and the wallpaper by simply removing this line from the plugin/src/main/AndroidManifest.xml file:

android:process="${applicationId}.wallpaper"

I didn't test this, so I'm not sure how well his will run with the rest of the plugin functionalities or if it run at all.

kplusan commented 3 weeks ago

I tried removing this line "android:process=...", but it still didn't work and always crash.

Sync data by storing changes may be good for small changes, but not suitable for complex scene. So it is best to use only one process(instances).

The only way I can find is to create two layouts.

while Activity.onCreate or Activity.onResume:
    if not CurrentWallpaper==APP:
        use layout_boot
        //contains a button for setting wallpaper
    else:
        use layout_run
        //an empty and transparent layout
        //in immersive mode
        //backgroud is the homescreen wallpaper

This allows us to use only one process, but there is still a problem: the APP cannot be run as a game alone, it can only be used when set as wallpaper.

Anyway, this is a great and excellent plugin. I waited for 2 years to see that Godot has something related to wallpapers. Thank you for your work. Looking forward to improvement.

Best regards.