较低版本的应用程序没有在Android的高级版本中运行

时间:2012-06-07 04:22:02

标签: java android debugging android-2.2-froyo

我使用android SDK 2.2版本制作了我的应用程序,现在当我在android SDK 4.0.3上运行我的应用程序时,它没有运行。

我在清单文件中给出了min和max sdk。

我是Android的新手,想要为更低版本和更高版本运行我的应用程序。谁能告诉我怎么能这样做呢。任何帮助表示赞赏。

初级类代码

package com.Cricket_trivia.in;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;

public class SplashScreen extends Activity {

    protected int _splashTime = 5000; 

    private Thread splashTread;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);


        final SplashScreen sPlashScreen = this; 

        // thread for displaying the SplashScreen
        splashTread = new Thread() {
            @Override
            public void run() {
                try {                   
                    synchronized(this){
                        wait(_splashTime);
                    }

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

                    Intent i = new Intent();
                    i.setClass(sPlashScreen, K_trivia_cricketActivity.class);
                    startActivity(i);

                    stop();
                }
            }
        };

        splashTread.start();
    }
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            synchronized(splashTread){
                splashTread.notifyAll();
            }
        }
        return true;
    }

}

编辑:我的logcat

    06-07 10:24:18.710: I/dalvikvm(1461): threadid=3: reacting to signal 3
    06-07 10:24:18.760: I/dalvikvm(1461): Wrote stack traces to '/data/anr/traces.txt'
    06-07 10:24:18.890: D/dalvikvm(1461): GC_FOR_ALLOC freed 45K, 4% free 6541K/6787K, paused 74ms
    06-07 10:24:18.900: I/dalvikvm-heap(1461): Grow heap (frag case) to 7.333MB for 921616-byte allocation
    06-07 10:24:19.010: I/dalvikvm(1461): threadid=3: reacting to signal 3
    06-07 10:24:19.100: I/dalvikvm(1461): Wrote stack traces to '/data/anr/traces.txt'
    06-07 10:24:19.140: D/dalvikvm(1461): GC_CONCURRENT freed <1K, 5% free 7440K/7751K, paused 5ms+5ms
    06-07 10:24:19.240: D/dalvikvm(1461): GC_FOR_ALLOC freed 0K, 5% free 7440K/7751K, paused 97ms
    06-07 10:24:19.240: I/dalvikvm-heap(1461): Grow heap (frag case) to 7.723MB for 409936-byte allocation
    06-07 10:24:19.320: D/dalvikvm(1461): GC_FOR_ALLOC freed 0K, 5% free 7841K/8199K, paused 61ms
    06-07 10:24:19.589: D/gralloc_goldfish(1461): Emulator without GPU emulation detected.
    06-07 10:24:19.669: I/dalvikvm(1461): threadid=3: reacting to signal 3
    06-07 10:24:19.779: I/dalvikvm(1461): Wrote stack traces to '/data/anr/traces.txt'
    06-07 10:24:24.600: W/dalvikvm(1461): threadid=11: thread exiting with uncaught exception (group=0x409c01f8)
    06-07 10:24:24.600: E/AndroidRuntime(1461): FATAL EXCEPTION: Thread-78
    06-07 10:24:24.600: E/AndroidRuntime(1461): java.lang.UnsupportedOperationException
    06-07 10:24:24.600: E/AndroidRuntime(1461):     at java.lang.Thread.stop(Thread.java:1076)
    06-07 10:24:24.600: E/AndroidRuntime(1461):     at java.lang.Thread.stop(Thread.java:1063)
    06-07 10:24:24.600: E/AndroidRuntime(1461):     at com.Cricket_trivia.in.SplashScreen$1.run(SplashScreen.java:40)
    06-07 10:24:26.209: D/dalvikvm(1461): GC_FOR_ALLOC freed 1037K, 15% free 7022K/8199K, paused 62ms
    06-07 10:24:26.209: I/dalvikvm-heap(1461): Grow heap (frag case) to 7.509MB for 614416-byte allocation
    06-07 10:24:26.440: D/dalvikvm(1461): GC_CONCURRENT freed <1K, 8% free 7621K/8199K, paused 4ms+5ms
    06-07 10:24:26.610: I/dalvikvm(1461): threadid=3: reacting to signal 3
    06-07 10:24:26.640: I/dalvikvm(1461): Wrote stack traces to '/data/anr/traces.txt'

2 个答案:

答案 0 :(得分:3)

您的应用程序崩溃4.0.3但不是2.2的原因很可能是因为您在UI线程上执行了昂贵的操作。 Blocking the UI thread is very bad practice... don't do it!!早期版本的Android(即ICS之前版本)并不关心您何时执行此操作并让您的应用按原样运行。但是,在4.0及更高版本中,如果您在UI线程上执行了可能很昂贵的操作(例如网络连接等),操作系统会对此进行检查并使您的应用程序崩溃。

您已经基本上提供了没有信息,告诉您问题中的问题,这就是我能帮到您的所有帮助。


编辑:

这样的事情有用吗?

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        Intent i = new Intent();
        i.setClass(sPlashScreen, K_trivia_cricketActivity.class);
        startActivity(i);
    }
    return true;
}

答案 1 :(得分:1)

你不是线程,因为它是在更高版本中创建问题。使用下面的代码显示启动画面。

   package com.Cricket_trivia.in;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.MotionEvent;

public class SplashScreen extends Activity {

    protected int _splashTime = 5000; 

    private Thread splashTread;
    MyCount counter = new MyCount(4000, 4000);
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        counter.start();
    }
     public class MyCount extends CountDownTimer
     {
         public MyCount(long csecond, long countDownInterval) 
         {
              super(csecond, countDownInterval);
         }

        @Override
        public void onFinish() {
            finish();
            Intent intent = new Intent();
            intent.setClass(SplashScreen.this, K_trivia_cricketActivity.class);
            startActivity(intent);

        }

        @Override
        public void onTick(long arg0) {
            // TODO Auto-generated method stub

        }
}
}


 I think it will work for you