Activity wont start with "startActivity();"
Here's my code for DroidArmoryActivity
package com.maxgenero.droidarmory;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
public class DroidArmoryActivity extends Activi开发者_开发问答ty implements View.OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()) {
case R.id.ibM4A1:
Intent intentM4A1 = new Intent("com.maxgenero.droidarmory.M4A1GUN");
startActivity(intentM4A1);
break;
}
}
}
It's not starting the java file (Activity) at all, no errors. Btw, the case is looking for an imageButton. Here's my Manifest, at least the part you need:
<activity android:name=".M4a1"
android:label="@string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="com.maxgenero.droidarmory.M4A1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
And the file name for the java file is M4a1.java. If you need more info let me know, thanks.
I dont see where you define a listener on your Button or your View that will be clicked to launch the second Activity ??
yourView.setOnClickListener(this);
the second thing is that you should add declare your activity on your manifest file on the tag like this :
<activity android:name="your.package.name.NameOfYourAcitivity" />
the last thing is : try to instantiate the intent like this :
this.startActivity(new Intent(this, SecondActivity.class));
Regards,
Instead of...
case R.id.ibM4A1:
Intent intentM4A1 = new Intent("com.maxgenero.droidarmory.M4A1GUN");
startActivity(intentM4A1);
Try
Intent intentM4A1 = new Intent(this, ACTIVITY_NAME.class);
startActivity(intentM4A1);
Also dont forget to call your setOnclickListener().
精彩评论