Android Question Simulating Restart Activity

DawningTruth

Active Member
Licensed User
My app needs to redraw certain elements upon a button press.

I have created an algorithm which requires the following steps:

B4X:
'Button Pressed
'Do some stuff
'Save Activity Data
'Restart Activity
'Redraw Based on Previous Activity Data

Some of the critical code is in Create and some of it is in Resume. So both need to be executed.

I have tried using:

B4X:
Activity_Pause

'Within Pause

Activity_Create

But it does not recreate the activity.

Any suggestions.
 

DawningTruth

Active Member
Licensed User
Use a your own sub like Sub Redraw, instead of trying to restart the activity (call Redraw also in Activity_Create, of course)
Thx LucasMS.

The nature of the views used requires a redraw. I already have the code that does what is required for the screen change orientation.

So in this case I basically need to trigger some sort of configuration change event, which mimics the Activity Lifecycle of a Screen Orientation Change i.e. Pause -> Create -> Resume
 
Upvote 0

Jack Cole

Well-Known Member
Licensed User
Longtime User
Semens approach is elegant.

I've done it before manually by just doing what the app already does when creating the activity. You have to remove all the views, and execute the subs that declare the variables (to reset them).

B4X:
Sub Restart
     Activity.RemoveAllViews
     Process_Globals
     Globals
     Activity_Create(True)
     Activity_Resume
End Sub
 
Upvote 0

DawningTruth

Active Member
Licensed User
Semens approach is elegant.

I've done it before manually by just doing what the app already does when creating the activity. You have to remove all the views, and execute the subs that declare the variables (to reset them).

B4X:
Sub Restart
     Activity.RemoveAllViews
     Process_Globals
     Globals
     Activity_Create(True)
     Activity_Resume
End Sub
Thx Jake, interesting alternative approach ;-)
 
Upvote 0

DawningTruth

Active Member
Licensed User
If you need to recreate the activity then your program is not structured ideally.
Best option is to rethink its structure.

You can restart it with:
B4X:
Activity.Finish
StartActivity(Me)
Thx Erel. I do agree with you. Am investigating an alternative.
 
Upvote 0
Top