-1

我已经使用 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;
    }

}

编辑:我的日志猫

    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'
4

2 回答 2

3

您的应用在 4.0.3 而不是 2.2 上崩溃的原因很可能是因为您在 UI 线程上执行了昂贵的操作。阻塞 UI 线程是非常糟糕的做法......不要这样做!以前的 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;
}
于 2012-06-07T04:42:15.637 回答
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
于 2012-06-07T06:27:56.530 回答