android - Activity 打不开

标签 android android-intent android-manifest

我有一个按钮可以在 Android 中打开一个新 Activity ,但它什么也没做。

第一个 Activity 的 Java:

public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.lists);


        }

 @Override
 public void onConfigurationChanged(Configuration newConfig) {
   // ignore orientation/keyboard change
   super.onConfigurationChanged(newConfig);


        ListView listsList = (ListView) findViewById(R.id.lists);  
       Button newList = (Button) findViewById(R.id.newlistbutton);
        newList.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                 Intent myIntent = new Intent(v.getContext(), NewWishList.class);
                 startActivity(myIntent);
            }
        });
 }
}

第二个 Activity 的 Java:

public class NewWishList extends Activity {

     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.newlist);

         Button back = (Button) findViewById(R.id.backbutton);
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    Intent intent = new Intent(view.getContext(), ListOfLists.class);
                    startActivity(intent);
                }

            });
     }
@Override
public void onConfigurationChanged(Configuration newConfig) {
  // ignore orientation/keyboard change
  super.onConfigurationChanged(newConfig);

  RadioGroup option = (RadioGroup) findViewById(R.id.radioGroup1);

}   
}

list :

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

<uses-sdk
    android:minSdkVersion="7" />

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

<uses-feature android:name="android.hardware.screen.portrait"/>


<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Black.NoTitleBar">
    <activity
        android:name="com.wish.list.FacebookSignIn"
        android:label="@string/app_name"
        android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action
                android:name="android.intent.action.MAIN" />

            <category
                android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

<activity 
    android:name=".ListOfLists"
    android:configChanges="orientation|keyboardHidden"
    android:screenOrientation="portrait"
    ></activity>

<activity 
android:name=".NewWishList"
android:configChanges="orientation|keyboardHidden"
    android:screenOrientation="portrait"
></activity>

</application>
</manifest>

Logcat 或错误日志中没有错误。这很奇怪。我有 onConfigurationChange 的原因是因为我将它设置为 Force Portrait Orientation on。 Activity 在 list 中定义。

最佳答案

首先,尝试使用

MyActivity.this 

对于上下文。

关于android - Activity 打不开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9899569/

相关文章:

android - 如何检查是否可以从某些 Activity 中处理 Intent ?

android - Android中的后台传感器数据收集器

android - org.json.JSONException : Value 10. 07526 at 0 of type java.lang.Double cannot be converted to JSONObject

android - SlidingDrawer handle 的位置?

java - 我如何将 Intent 方法插入到此代码中,以便单击按钮时它将显示第二个 Activity

android - 是否可以在android(系统菜单)的上下文菜单中添加一些项目

android - Galaxy Note 上 Facebook 请求对话框的持续网络错误

android - IllegalStateException : parcel. readString() 不能为空

android - 如何指定Android APK中某些文件的目标路径?

java - 无法在我的应用中播放 YouTube 视频