Reputation: 334
I've got this code in my app that after five seconds open another activity.
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(R.layout.activity_game);
}
},5000);
But Eclipse doesn't like this...:
View error message: https://i.sstatic.net/Zh8Id.png
But when I choose one of those methods, Eclipse wants the startActivity() again!
What can I do?
Upvotes: 0
Views: 81
Reputation: 11
Do something like
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(this, ActivityGame.class);
startActivity(intent);
}
}, 5000);
instead.
Upvotes: 1
Reputation: 656
To start activity use this:
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(i);
If you are using Fragment
try getActivity();
instead of FirstActivity.this
, or if you in normal activity try getApplicationContext();
instead of FirstActivity.this
or just use this
.
Upvotes: 3
Reputation: 2618
if is this Fragment
then use
getActivity().startActivity(new Intent(getActivity(),YOURACTIVITY.class));
and if is this activity
then
startActivity(new Intent(currentActivity.this,YOURACTIVITY.class));
Upvotes: 1
Reputation:
You need to create an intent:
startActivity(new Intent(CurrentActivity.this, NewActivity.class));
Upvotes: 1