Reputation: 13
I'm a beginner to Android development, and am creating an offline app. I have three activities. The first activity screen splashes to next activity after two seconds, after that when I click a button in the second activity it is not moving to the third activity.
Actually it had worked before I added this splashing concept. When I tried to implement this I just modified the code and that's working well for the timer but not for the other..
Here's my code for all activities:
MainActivity.java:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
final Intent mainIntent = new Intent(MainActivity.this, MainActivity1.class);
MainActivity.this.startActivity(mainIntent);
MainActivity.this.finish();
}
}, 2000);
}
}
MainActivity1.java:
Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main1);
addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, MainActivity2.class);
startActivity(intent);
}
});
}
}
Upvotes: 1
Views: 103
Reputation: 4092
If you created activity class means, you must declare the activity in manifest file.Otherwise the activity should not be invoke or it show error in Run-time.
Manifest file
<activity
android:name=".MainActivity2">
</activity>
Upvotes: 1