-1

I have made my application using android SDK 2.2 version and now when I am running my app on android SDK 4.0.3 it's not running.

I have given the min and the max sdk in the manifest file.

I am new in android and want to run my app for the lower and higher versions both. Can anybody tell me how can I do this. Any help is appreciated.

Code for splash class

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

}

EDIT: My 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'
Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
ADB
  • 567
  • 2
  • 5
  • 20

2 Answers2

3

The reason why your app is crashing on 4.0.3 but not 2.2 is most likely because you are performing an expensive operation on the UI thread. Blocking the UI thread is very bad practice... don't do it!! Previous versions of Android (i.e. pre-ICS versions) didn't care when you did this and let your app run as is. In 4.0 and above, however, the OS checks against this and crashes your app if you ever perform a potentially expensive operation on the UI thread (such as a network connection, etc.).

You have provided basically no information on what the problem is in your question, so that's all I can really do to help you out.


Edit:

Does something like this work?

/** 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;
}
Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
  • my log cat when I run my app in the 4.0.3 version – ADB Jun 07 '12 at 04:57
  • You need to provide us with some code. There isn't much to tell from the logcat you've posted. – Alex Lockwood Jun 07 '12 at 04:58
  • The solution is to rid your `Activity` of `Thread`s all together. They are not necessary for what you are trying to do. Simply call `startActivity()` when you perform the `onTouchEvent()`. Calling `finish()` just before you make a call to `startActivity()` doesn't make much sense either. You probably don't want your code to have any call to `finish()` from what I can tell. – Alex Lockwood Jun 07 '12 at 05:21
1

Don't you threads because it is creating the problem in the higher version. Use the code below to show the splash screen.

   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
Naresh Sharma
  • 4,323
  • 7
  • 48
  • 68
  • @Shifu, This looks like a complete hack to me. You should understand how your code works instead of assuming that it works correctly just because it doesn't crash. Why do you even need threads/timers in the first place? – Alex Lockwood Jun 07 '12 at 12:18
  • @AlexLockwood after doing this the app running well in the upper version as well and I am not aware with the fact that we should use the timer/threads in splash or not. – ADB Jun 07 '12 at 12:25
  • Can you explain to me why you chose to use timers/threads? Just because your app doesn't crash it doesn't mean you are doing it wrong. As far as I can tell, the code above is equivalent to using `sleep(4000)` to avoid race conditions... – Alex Lockwood Jun 07 '12 at 12:30
  • It's fair to the people who come back to this question later looking for an answer to a similar question. I strongly disagree with this answer, even if it worked for the OP. Sorry if it resulted in -2 points, but I don't want people to do something similar in their apps thinking that it is the correct answer. – Alex Lockwood Jun 07 '12 at 13:24
  • I upvoted a couple of your top answers... I hope that makes up for it :). – Alex Lockwood Jun 07 '12 at 13:24
  • @AlexLockwood May be i am wrong and don't hv the knowledge like u. But i am trying to solve the problem of that Guy. Also i believe to get the points only when my ans and que help them, not like that you have given. :( – Naresh Sharma Jun 07 '12 at 13:30
  • @AlexLockwood what r u doing man. You have just make fun of mine by doing activity like that. Stop doing this – Naresh Sharma Jun 07 '12 at 13:33
  • OK, I unupvoted your answers. I still think this answer is completely wrong, sorry if you don't feel the same way. The faq states, "Use your downvotes whenever you encounter an egregiously sloppy, no-effort-expended post, or an answer that is clearly and perhaps dangerously incorrect." " – Alex Lockwood Jun 07 '12 at 13:37
  • @AlexLockwood Ok i will take care of this thing and thanks for your kind suggestion. But i am not in a race of getting reputations and want to learn as much as possible – Naresh Sharma Jun 07 '12 at 13:43
  • I thought you were, since you didn't like that I downvoted your post... that's the only reason why I did it :). – Alex Lockwood Jun 07 '12 at 13:44
  • @AlexLockwood i want to discuss about the threads/Timer with you can we talk in any chat room. – Naresh Sharma Jun 07 '12 at 13:51
  • @AlexLockwood from 9AM to 8PM i m in No Holds Barred room. Came in that room when you find any time – Naresh Sharma Jun 07 '12 at 13:56