android 2.3.3没有在android 4.0.3上运行

时间:2013-02-22 07:12:53

标签: android

我正在开发一个使用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 个答案:

答案 0 :(得分:0)

您使用的是4.0.3中不推荐使用的方法,但2.3.3中没有。基本上2.3.3有功能但4.0.3没有。无论Splash第48行的功能是什么,都需要删除。

答案 1 :(得分:0)

在Android中,最好使用Handler来管理ThreadRunnables

创建一个处理程序实例

Handler handler = new Handler();

创建一个Runnable线程

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);

答案 2 :(得分:0)

尝试使用Runnable Thread

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


        //do your things here


        }
  });
  splashThread.start();

修改

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

答案 3 :(得分: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
        }
    }
}