所以我试图使用Intents切换视图,我之前已经能够正常工作但现在它只是保持关闭,这也是通过菜单按钮,继承我的菜单代码:
public boolean onCreateOptionsMenu(android.view.Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater blowUp = getMenuInflater();
blowUp.inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.stats:
Intent i = new Intent("com.mittereder.rockpaper.STATS");
startActivity(i);
break;
}
return false;
}
这是我的菜单,其中包含该项目:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/stats"
android:alphabeticShortcut="s"
android:title="Stats"/>
</menu>
然后这是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mittereder.rockpaper"
android:versionCode="2"
android:versionName="1.2" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/stop"
android:label="@string/app_name" >
<activity
android:name=".start"
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=".stats"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.mittereder.rockpaper.STATS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
我一遍又一遍地查看我的代码,我不知道我错过了什么。
logcat的:
08-09 11:51:11.471: E/AndroidRuntime(13384): FATAL EXCEPTION: main
08-09 11:51:11.471: E/AndroidRuntime(13384): android.app.SuperNotCalledException: Activity {com.mittereder.rockpaper/com.mittereder.rockpaper.start} did not call through to super.onPause()
08-09 11:51:11.471: E/AndroidRuntime(13384): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3103)
08-09 11:51:11.471: E/AndroidRuntime(13384): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3062)
08-09 11:51:11.471: E/AndroidRuntime(13384): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3035)
08-09 11:51:11.471: E/AndroidRuntime(13384): at android.app.ActivityThread.access$800(ActivityThread.java:139)
08-09 11:51:11.471: E/AndroidRuntime(13384): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1268)
08-09 11:51:11.471: E/AndroidRuntime(13384): at android.os.Handler.dispatchMessage(Handler.java:99)
08-09 11:51:11.471: E/AndroidRuntime(13384): at android.os.Looper.loop(Looper.java:154)
08-09 11:51:11.471: E/AndroidRuntime(13384): at android.app.ActivityThread.main(ActivityThread.java:4945)
08-09 11:51:11.471: E/AndroidRuntime(13384): at java.lang.reflect.Method.invokeNative(Native Method)
08-09 11:51:11.471: E/AndroidRuntime(13384): at java.lang.reflect.Method.invoke(Method.java:511)
08-09 11:51:11.471: E/AndroidRuntime(13384): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-09 11:51:11.471: E/AndroidRuntime(13384): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-09 11:51:11.471: E/AndroidRuntime(13384): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:2)
看起来你的Start Activity会覆盖onPause并且不会调用超类。在启动stat活动之前,会在启动活动上调用onPause。