Android Firing Intent From Thread
I have created a thread for a game where I am testing if hero (a bitmap) touches the edges of the screen. Part of the Thread: protected void updatePhysics() { mBallX += elapsed * m
Solution 1:
The first parameter of Intent's constructor is a Context. You must pass the activity where the Thread is being executed, for instance:
Intent intent_btn_gameover = new Intent(NameOfActivity.this, GameOver.class);
startActivity(intent_btn_gameover);
If the thread is not inside an activity, you must pass somehow a reference to the activity that executes it.
Solution 2:
If you are starting an activity from your Thread and you have context then you should do like
Intent intent = new Intent(contextOfSourceClass,YourTargetActivity.class);
contextOfSourceClass.startActivity(intent);
because method startActivity(Intent intent) belongs to context class
we are able to call this method directly from our activity because Context is super parent class of Activity in Hierarchy.
Post a Comment for "Android Firing Intent From Thread"