0

I'm developing an app that uses minSdkVersion=10 for gingerbread. it is working fine on all gingerbread devices but when I try to run it on 4.0.3 emulator(ICS) it always stops. is there any settings I need to adjust?

here is my manifest

<?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" />

and the error on logcat is this

  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)

splash activity

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

}
Jerome
  • 79
  • 1
  • 8

4 Answers4

0

You're using a method that is deprecated in 4.0.3, but not in 2.3.3. Basically 2.3.3 has the function but 4.0.3 does not. Whatever the function is that is on line 48 in Splash is the method you need to remove.

Michael
  • 3,334
  • 20
  • 27
0

In Android its better to use Handler for managing the Thread and Runnables

Create an Handler instance

Handler handler = new Handler();

Create a Runnable thread

Runnable runnable = new Runnable() {

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

And start the Runnable using Handler

handler.postDelayed(runnable, 1000);

And to stop the Runnable use

handler.removeCallbacks(runnable);
Rahul Gokani
  • 1,688
  • 5
  • 25
  • 43
  • Try above thing I just found. And check that if its working or not and let me know. **I have just updated the Answare** – Rahul Gokani Feb 22 '13 at 08:12
0

Try use Runnable Thread instead

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


        //do your things here


        }
  });
  splashThread.start();

EDIT

You don't have to include stop(); in your thread. Your Thread will stop once it completed it tasks. Unless you use Thread.sleep();

IssacZH.
  • 1,457
  • 3
  • 24
  • 54
0

try below code, it work for me in all Android version.

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
        }
    }
}
Hasmukh
  • 4,632
  • 2
  • 30
  • 44