I am extending a thread class and from that class I want to start an activity. How to do this?
See Question&Answers more detail:osI am extending a thread class and from that class I want to start an activity. How to do this?
See Question&Answers more detail:osYou need to call startActivity()
on the application's main thread. One way to do that is by doing the following:
Initialize a Handler
and associate it with the application's main thread.
Handler handler = new Handler(Looper.getMainLooper());
Wrap the code that will start the Activity
inside an anonymous Runnable
class and pass it to the Handler#post(Runnable)
method.
handler.post(new Runnable() {
@Override
public void run() {
Intent intent = new Intent (MyActivity.this, NextActivity.class);
startActivity(intent);
}
});