Java Android开发线程问题
我正在eclipse中制作一个android应用程序,我的问题是,每次我在模拟器上运行它时,它都会在5秒钟后关闭,并给我一条消息“不幸的是,‘应用程序名称’已经停止工作”。我想这是因为线程会显示我放在drawable hdpi文件夹中的图片,因为线程会显示图片5秒钟,然后启动程序。非常感谢您的帮助Java Android开发线程问题,java,android,eclipse,multithreading,Java,Android,Eclipse,Multithreading,我正在eclipse中制作一个android应用程序,我的问题是,每次我在模拟器上运行它时,它都会在5秒钟后关闭,并给我一条消息“不幸的是,‘应用程序名称’已经停止工作”。我想这是因为线程会显示我放在drawable hdpi文件夹中的图片,因为线程会显示图片5秒钟,然后启动程序。非常感谢您的帮助 package com.thenewboston.travis; import android.app.Activity; import android.content.Intent; import
package com.thenewboston.travis;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity{
@Override
protected void onCreate(Bundle t) {
// TODO Auto-generated method stub
super.onCreate(t);
setContentView(R.layout.splash);
new Thread(){
public void run(){
try{
sleep(5000);
}catch(Exception e){
e.printStackTrace();
}finally{
Intent openStartingPoint= new Intent("com.thenewboston.travis.STARTINGPOINT");
startActivity(openStartingPoint);
}
}
}.start(); }}
Android清单代码
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.thenewboston.travis"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.thenewboston.travis.Splash"
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="com.thenewboston.travis.startingPoint"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这是我的启动文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/yaron_dynamics">
</LinearLayout>
您不能在与UI线程不同的线程中启动活动您不能从后台线程启动活动。使用处理程序而不是线程
:
Runnable r = new Runnable() {
public void run() {
Intent i = new Intent("com.thenewboston.travis.STARTINGPOINT");
startActivity(i);
}
};
new Handler().postDelayed(r, 5000);
应该是默认的。还有新的意图(com.thenewboston.travis.startingPoint)第一个活动正在工作,但第二个活动似乎从未启动,这就是导致程序结束的原因。我如何在处理程序之后调用startingPoint文件?无论您在开始活动之前做了什么:)这里,editedSo我删除了前一个线程,添加了上面的代码,并将清单中的第二个活动更改为默认值,但5秒后它仍然关闭,并向我提供了该消息。然后问题就在别处了。可能是您启动的第二个
活动。也许的意图是错误的。例如,我看到您将活动
称为开始点
(大写)和开始点
第一个活动正在工作,但第二个活动似乎从未启动,这是导致程序结束的原因。如何在处理程序之后调用startingPoint文件?第一个活动正在工作,但第二个活动似乎从未启动,这就是导致程序结束的原因。如何在处理程序之后调用startingPoint文件?