我正在创建一个小型android项目。我是Java和android的新手。当尝试在初始启动5秒后在android应用程序中打开另一个 Activity 时,而不是打开意图中提到的 Activity ,我的应用程序已关闭。
我的用于打开另一个意图的Java代码如下所示,用于打开 Activity 。
Thread timer = new Thread() {
@Override
public void run() {
try {
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent openStartingPoint = new Intent("com.mycompany.trial2.Third Activity");
startActivity(openStartingPoint);
}
}
};
最佳答案
意向中的类(class)名称中有一个空格。我认为这就是问题所在。
您应该替换为:
Intent openStartingPoint = new Intent("com.mycompany.trial2.Third Activity");
与
Intent openStartingPoint = new Intent("com.mycompany.trial2.ThirdActivity");
名称中的该空间将导致ActivityNotFound异常并关闭您的应用程序。
还要检查是否已在AndroidMAnifest.xml中声明了此 Activity ,这也可能导致问题。
如果这不是问题,请发布您的日志。
关于java - 应用程序关闭Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28577975/