Programmatically restarting an App

airblaster

Active Member
Licensed User
B4X:
Activity.Finish
   Dim r, r2 As Reflector
   r.Target = r.GetActivity
   r.Target = r.RunMethod("getApplicationContext")
   r2.Target = r.RunMethod("getPackageManager")
   Dim i As Intent = r2.RunMethod2("getLaunchIntentForPackage", r.RunMethod("getPackageName"), "java.lang.String" )
   r.Target = i
   r.RunMethod2("addFlags",  67108864, "java.lang.int")
   StartActivity(i)
 

eelias

Active Member
Licensed User
B4X:
Activity.Finish
   Dim r, r2 As Reflector
   r.Target = r.GetActivity
   r.Target = r.RunMethod("getApplicationContext")
   r2.Target = r.RunMethod("getPackageManager")
   Dim i As Intent = r2.RunMethod2("getLaunchIntentForPackage", r.RunMethod("getPackageName"), "java.lang.String" )
   r.Target = i
   r.RunMethod2("addFlags",  67108864, "java.lang.int")
   StartActivity(i)
Hi there, is it possible to give an example of use of you code?

I have an app that load configuration from a server, and if the configuration is changed i need to restart to draw the views in the new style.

Thanks

Eduardo
 

eelias

Active Member
Licensed User
You can restart the current activity with these two lines:
B4X:
Activity.Finish
StartActivity(Me)
Sorry the obvious question, however I am not sure how to use it.

I have added these 2 lines on my code, the app is finished but does not get started back again.

What else is needed?

Thanks
 

udg

Expert
Licensed User
Hi all,

I'm developing a library to automate app updating.
It would be nice to add some code capable of restarting the update version of the running app.
How have I to modify (if any) your code for that? And where should I put it?

TIA

Umberto
 
Top