Android:onBackPressed()导致应用程序崩溃
我试图使用android提供的onBackPressed()方法Android:onBackPressed()导致应用程序崩溃,android,android-intent,android-activity,Android,Android Intent,Android Activity,我试图使用android提供的onBackPressed()方法 <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> 我正在使用onBackPressed()方法的类: import com.interviewme.R; import android.os.Bu
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
我正在使用onBackPressed()
方法的类:
import com.interviewme.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class Preparing extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preparation);
}
@Override
public void onBackPressed() {
Intent t = new Intent(this, Menu.class);
startActivity(t);
}
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
}
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
清单文件中我试图返回的部分:
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
我注意到它声明了
ActivityNotFound
,但是这个Activity
肯定在我的应用程序中,它在清单中的名称是否不正确?您导入了android.view.Menu
。试着写出com.interviewme.Menu
。为你的活动使用更好的名称。菜单有点模棱两可。它的默认菜单
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
删除此行
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
import android.view.Menu;
并导入您的类或将“类名”菜单更改为其他名称(如Menu1)显示错误,原因如下:-
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
import android.view.Menu;
Intent t = new Intent(this, Menu.class);
startActivity(t);
您的代码选择view.Menu
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
您必须使用:-
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Intent t = new Intent(this, com.interviewme.Menu.class);// where menu class here
startActivity(t);
而不是这个
android:name=“.Menu”
在清单中写入com.interviewme.Menu
,然后再试一次。这是我以前使用的,它仍然会导致应用程序将您的菜单类折叠在同一个包中。请将您的菜单类重命名为MyMenu,因为我认为这是个问题,您使用的是保留菜单名。