I've tried and failed repeatedly to simply have my Android emulator go from one activity to another in a program. Each attempt suddenly forces the app to close.

Here is my code for the two activites:

package dg.exe;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Dungeon_Main_Menu extends Activity {
	private Dungeon_Main_Menu mContext;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        
        setContentView(R.layout.main);
        
        Button DiceRollerButton = (Button)findViewById(R.id.DiceRollerButton);
        
        DiceRollerButton.setOnClickListener(new OnClickListener(){
			public void onClick(View arg0) {
				Intent i = new Intent(Dungeon_Main_Menu.this, Dungeon_Dice_Roller.class);
				startActivity(i);
				//setContentView(R.layout.diceroller);				
			}
        	
        });
    }
}

And the second part...

package dg.exe;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;

public class Dungeon_Dice_Roller extends Activity{
	private Dungeon_Dice_Roller mContext;
	
	public void onCreate(Bundle savedInstanceState){
		mContext = this;
		
		setContentView(R.layout.diceroller);	
		Button returnButton = (Button)findViewById(R.id.returnbutton);
		
		returnButton.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				mContext.finish();
			}
			
		});
	}
	
}

Recommended Answers

All 3 Replies

Updated. Found out the problem has to do with the AndroidManifest.xml but I can't figure out what to do... any ideas?

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="dungen.exe"
      android:versionCode="1"
      android:versionName="1.0">


    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Dungeon_Main_Menu"
                  android:label="@string/app_name">
                
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <activity android:name="Dungeon_Dice_Roller"
        		  android:label="Dungeon_Dice_Roller">
        </activity>


    </application>
</manifest>

Instead of android:name="Dungeon_Dice_Roller" try this:
android:name=".Dungeon_Dice_Roller"

The dot (.) is important as it denotes the class name which will be appended to the package name by the compiler.

Gotta love something simple like that. I'll try that when I'm home, thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.