我正在创建一个小型的android项目。我是java和android的新手。在初始启动5秒后尝试在Android应用程序中打开另一个活动时,我的应用程序将关闭,而不是打开intent中提到的活动。
我打开另一个意图的java代码如下所示,即要打开的活动。
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);
}
}
};
答案 0 :(得分:1)
您的意图中的类名称中有一个空格。我认为这是在制造问题。
你应该替换它:
Intent openStartingPoint = new Intent("com.mycompany.trial2.Third Activity");
与
Intent openStartingPoint = new Intent("com.mycompany.trial2.ThirdActivity");
名称中的这个空格会导致ActivityNotFound异常并关闭您的应用程序。 还要检查你是否在AndroidMAnifest.xml中声明了这个活动,这也可能导致问题。
如果这不是问题,请发布您的logcat。
答案 1 :(得分:0)
There was two chances for problems.
1. you didn't register your activity in android manifest file. so, Register your activity in manifest file.
2.Try the following code
Intent openStartingPoint = new Intent("SecondActivity.this,ThirdActivity.class");
startActivity(openStartingPoint);