Android Question Auto start app after self update

Status
Not open for further replies.

AscySoft

Active Member
Licensed User
Longtime User
Hello. Let me be direct.
I put the following code in manifest editor
B4X:
AddReceiverText(AutoStartApp, <intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
 </intent-filter>)
My "AutoStartApp" service is as simple as this
B4X:
#Region  Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
End Sub
Sub Service_Create
    Log("..........APP SELF UPDATED OK, RESTARTING...........")
    StartActivity(Main)
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Sub Service_Destroy
End Sub
That's it
Now, i test this on two phones (Note 3- Android 5, and another samsung A 2017 with Android 8)
In neither one of them the app will NOT start after self update (downloaded from server, installing using FileProvider all OK) but it refuse to restart after update.
Solution?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'am asking you politely in what environment/setup you were able to test it with success
Windows environment is not relevant. It was tested on Android 10.

I tried it again.
Here are the exact steps and the logs:

1. Download the example I've previously uploaded.
2. Run it in release mode.
3. Click on the home button.
4. Reinstall the APK with ADB as explained in my previous post.

** Receiver (packagereplaced) OnReceive **
*** Service (starter) Create ***
** Service (starter) Start **
*** Service (packagereplaced) Create ***
** Service (packagereplaced) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Receiver (packagereplaced) OnReceive ** <-------- after the call to adb
*** Service (starter) Create ***
** Service (starter) Start **
** Service (packagereplaced) Create **
** Service (packagereplaced) Start **
Service started in foreground mode.
 
Upvote 0

AscySoft

Active Member
Licensed User
Longtime User
This is working for me as well (now that you show exactly how to test it)
If i put the 1.apk in assets folder, extract it to an external folder (similat to downloading new apk to external folder) then install it from app itself (no adb command), do you think it will restart after self update?
 
Upvote 0

AscySoft

Active Member
Licensed User
Longtime User
I've done it already. It works. Also I did make an error starting this thread, because the testing app downloaded from my ftp server and replaced over the current one was not correct (not updated), that's way it never worked;
I post here a modified version with working self update from Assets and auto-restarted (althoug note that in some cases, don't know why, the log saying "app self updated OK" is not colored yellow as in my code, but white, sugesting that....??!!??)
And also, after a few consecutive self updates with successfully restart, at some point app will not restart but getting crash,
ie the 3rd time will not restart after successefully update, starting it...then
the 4th time after repeating the test it will crush as it refuse to work with FileProvider...
So app is not perfect, but I guess a developper will not release newer updates at this rate!

PS: As I cannot upload project here 3MB large, you need to bulild it in release mode, then copy APK (3MB) to your assets folder, and the install to a real device.
 

Attachments

  • screen.png
    screen.png
    208 KB · Views: 200
  • self_upd_restart_ok.zip
    10.8 KB · Views: 217
Upvote 0

mading1309

Member
Licensed User
Longtime User
Thanks for the simple and very effective way to inform the user that he/she/it is using a new version
Just use the Manifest entry and referenced to a service that will be started in case of a new version or new installation
 
Upvote 0
Status
Not open for further replies.
Top