user264953
user264953

Reputation: 1967

Restarting Application using broadcast - Android

I am working with Android open source code. I am modifying the Launcher application such that the Launcher and homescreen Icons can be changed through an application.

Now, I have an issue here. In order for the Launcher icons to refresh after pressing the 'Apply new icons' button from the app, I need to restart the Launcher - onDestroy, then onCreate.

Observing the open source workflow after inserting logs, I observed that, the following callback sequence is executed in the case of restarting the launcher during Locale change.

I understand, Locale change is in some way related to ACTION_CONFIGURATION_CHANGED and whenever it happens, Launcher is restarted using the sequence given in log.

In order to substantiate my point that Launcher is restarted on Locale changed, I did the following test. I did 'Apply new icons' and checked home screen, icons are not changed, then I changed the Language and came back to home screen, and icons were changed! Also, the log indicates clearly, Launcher is restarted during Locale change.

01-01 00:02:19.960: INFO/ActivityManager(264): app/com.android.launcher[RESUMED]  app.idle/true ...resumeTopActivityLocked
01-01 00:02:19.968: DEBUG/Launcher(564): ****Inside  onRetainNonConfigurationInstance()****
01-01 00:02:19.968: DEBUG/Launcher(564): ****Inside onDestroy()****
01-01 00:02:19.968: DEBUG/LauncherApplication(564): setLauncher
01-01 00:02:19.968: DEBUG/Launcher(564): ****Inside unbindWorkspaceAndHotseatItems()****
01-01 00:02:19.992: DEBUG/Launcher(564): ****Inside onWindowVisibilityChanged()****
01-01 00:02:19.992: DEBUG/Launcher(564): ****Inside updateRunning()**** autoAdvanceRunning = false
01-01 00:02:19.992: DEBUG/Launcher(564): ****Inside onDetachedFromWindow()****
01-01 00:02:19.992: DEBUG/Launcher(564): ****Inside updateRunning()**** autoAdvanceRunning = false
01-01 00:02:19.992: DEBUG/Launcher(564): ****Inside AppWidgetResetObserver()****
01-01 00:02:19.992: DEBUG/Launcher(564): ****Inside onCreate()****

The question I have here is, after pressing the 'Apply new icons' from the external application, can I explicitly invoke the Broadcast Action ACTION_CONFIGURATION_CHANGED ? If yes, the Launcher will be restarted using the log sequence I gave, and I have my new icons in the home screen and my issue is resolved.

Any help is much appreciated.

Upvotes: 0

Views: 596

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006664

can I explicitly invoke the Broadcast Action ACTION_CONFIGURATION_CHANGED ?

No. Quoting the documentation, "This is a protected intent that can only be sent by the system."

If yes, the Launcher will be restarted using the log sequence I gave

Not necessarily. You assume that the broadcast is the trigger for "the log sequence I gave". Correlation does not imply causation.

Since you are modifying the launcher, you are welcome to have it respond to some other custom broadcast Intent of yours, which your other app sends. You are then welcome to respond to that broadcast by manually reloading all things that might have changed.

Upvotes: 1

Related Questions