The problem I am having is that the onCreate() method within my MainActivity cannot seem to start another activity.
I have code working so that when I click a button
Your AboutActivity class...
public class AboutActivity extends MainActivity {
Please change it to:
public class AboutActivity extends Activity {
and as others noted, when constructing your intent, use this, or MainActivity.this.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Fire the intent that launches the "About" screen.
Intent i= new Intent(this, AboutActivity.class);
startActivity(i);
I just realized what the problem is.
The issue is that the AboutActivity is causing the intent to fire repeatedly. The first line in the AboutActivity's onCreate() is super.onCreate(savedInstanceState). This means that application control will go back to the MainActivity's onCreate() where the intent will then be fired again. Therefore, I seem to have caused an infinite loop of intent calling.
I will post the solution if I find it.
Try passing this
instead of getBaseContext()
to the intent.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Fire the intent that launches the "About" screen.
Intent aboutScreen = new Intent(this, AboutActivity.class);
this.startActivity(aboutScreen);
}
Try this instead:
Intent aboutScreen = new Intent(MainActivity.this, AboutActivity.class);
this.startActivity(aboutScreen);