Reputation: 361
I am making a game for Android, but I never really found a good way to change the activities, or the content views. I have 1 main menu activity now, whose content view receives MotionEvent
s and dispatches them to my custom buttons. Another Activity
has a simple contentView
which just paints the screen in one color. All contentView
s have the same base class and activity 2 is derived from activity 1.
The problem is, that the app just crashes if a try to change the activity. It takes about 20 seconds, then the error message appears that says the app isnt responding.
In logcat, theres also a message keyDispatchingTimedOut sending to activity2
Below is the code for activity change:
public void changeActivity() {
Log.d("changing", "activity");
Intent i=new Intent(this, Activity_Level.class);
startActivity(i);
}
Any ideas?
Upvotes: 0
Views: 119
Reputation: 116382
if the app isn't responding , it's because you do a long operation on the UI thread . maybe after calling this function you continue to do something else ?
if , as people said , the activity isn't opened (and you can check it by writing to the log inside the onCreate method) , check the manifest.
in any case , if you want to have better control of activities , you can check the possible flags to use for the intents , and you can also use fragments (when possible) , just like google recommends .
Upvotes: 1
Reputation: 3370
You have to use context of your activity in method
Intent i=new Intent(Youar_Activity_Name.this, Activity_Level.class);
^^^^^^^^^^^^^^^^^^^^^^
Use above code in your changeActivity() method.
Upvotes: 1
Reputation: 1684
I sense that you didn't add all the activities to the manifest.xml
file. Try to add all the activities there, and give it a run.
Upvotes: 0
Reputation: 6237
Without seeing the logcat message, I bet you forgot to add the activity in AndroidManifest.xml
Upvotes: 0