java - Ending an activity on a background thread -


I assume that it will call to end () on one activity from a thread Poor practice is not UI threads I need to end an activity when a certain event (rendering / loop is calculated in the thread).

According to the answer to this type of question, using a handler, the UI thread is appropriate. I tried to do this but the activity never ended - should I do something before posting, or what Should I use a completely different method?

By default, the handler (looper) is created on the thread which is installed on them. To ensure that the handler is on the main UI thread, you can:

  handler myHandler = new handler (Looper.getMainLooper ());   

Then, to post the item on the main thread, create a class that executes the Runnable interface, then post to the handler

  myHandler.post (new Runnabel) {@Override public void run ()} {code to run on UI code}}});   

Another easy grandma move you can post on a view which is visible to your activity. For example, see your root view MyView = findViewById (R.id.myViewId); Runnabal Runnabalject = New MyRunnableObject (); MyView.post (runnableObject);

Some things to note about all the things posted on the UI thread will be displayed. View will not be executed until view > is on the tree . You can post Runnables in your view , and then they can all see the view by checking the user. It should also be noted that this is not particularly easy to cancel Runnable s which are posted in the view. They internally use a handler, but remove ____ () methods are completely all.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -