0

我正在开发一个将 minSdkVersion=10 用于姜饼的应用程序。它在所有姜饼设备上运行良好,但是当我尝试在 4.0.3 模拟器(ICS)上运行它时,它总是停止。我需要调整什么设置吗?

这是我的清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.das"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="15" />

logcat 上的错误是这样的

  02-22 15:03:40.217: E/global(514): Deprecated Thread methods are not supported.
02-22 15:03:40.217: E/global(514): java.lang.UnsupportedOperationException
02-22 15:03:40.217: E/global(514):  at java.lang.VMThread.stop(VMThread.java:85)
02-22 15:03:40.217: E/global(514):  at java.lang.Thread.stop(Thread.java:1280)
02-22 15:03:40.217: E/global(514):  at java.lang.Thread.stop(Thread.java:1247)
02-22 15:03:40.217: E/global(514):  at         com.example.SpelloGrande.splash$1.run(splash.java:48)

飞溅活动

public class splash extends Activity {

//how long until we go to the next activity
protected int _splashTime = 3000; 

private Thread splashTread;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    final splash sPlashScreen = this; 

    // thread for displaying the SplashScreen
    splashTread = new Thread() {

        @Override
        public void run() {
            try {
                synchronized(this){

                        //duration
                        wait(_splashTime);

                }

            } catch(InterruptedException e) {}
            finally {
                finish();

                //start a new activity
                Intent i = new Intent();
                i.setClass(sPlashScreen, MainActivity.class);
                        startActivity(i);

                stop();
            }
        }
    };

    splashTread.start();
}

//Function that will handle the touch
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        synchronized(splashTread){
                splashTread.notifyAll();
        }
    }
    return true;
}

}
4

4 回答 4

0

试试下面的代码,它适用于所有 Android 版本。

public class Act_Splashscreen extends Activity
{
    private int delay = 5000;

    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);

        try
        {

            Timer timer = new Timer();
            TimerTask task = new TimerTask() 
            {
                @Override
                public void run() 
                {
                    // TODO Auto-generated method stub

                    Intent intent = new Intent(Act_Splashscreen.this, newactivity.class);
                    startActivity(intent);
                    finish();
                }

            };

            timer.schedule(task, delay);
        } catch (Exception e) {
            // TODO: handle exception
        }
    }
}
于 2013-02-22T07:35:38.547 回答
0

您使用的方法在 4.0.3 中已弃用,但在 2.3.3 中未弃用。基本上 2.3.3 有这个功能,但 4.0.3 没有。无论 Splash 中第 48 行的功能是什么,都是您需要删除的方法。

于 2013-02-22T07:17:55.047 回答
0

在 Android 中,它更好地Handler用于管理ThreadRunnables

创建一个处理程序实例

Handler handler = new Handler();

创建一个可运行线程

Runnable runnable = new Runnable() {

        @Override
        public void run() {
            Log.d("runnable started", "inside run");
            handler.removeCallbacks(runnable);
            handler.postDelayed(runnable, 1000);
        }
    };

并使用 Handler 启动 Runnable

handler.postDelayed(runnable, 1000);

并停止 Runnable 使用

handler.removeCallbacks(runnable);
于 2013-02-22T07:18:27.963 回答
0

尝试使用 Runnable Thread

  splashThread = new Thread(new runnable(){
        public void run(){


        //do your things here


        }
  });
  splashThread.start();

编辑

您不必包括 stop(); 在你的线程中。一旦完成任务,您的线程将停止。除非你使用 Thread.sleep();

于 2013-02-22T07:21:42.043 回答