Search code examples
androidandroid-4.0-ice-cream-sandwich

Code works on Gingerbread (2.3.6) not on ICS (4.0.4)


  • I have an application which was developed and tested on Android 2.3.6 and before and below. It works fine.
  • I Run the app on my new Micromax A110 with Android 4.0.4 and it crashes when i launch activity B from Activity A and press the back button (or Activity C/D/E from A ) with the following error log vv

01-10 18:35:44.372: E/AndroidRuntime(18378): FATAL EXCEPTION: Timer-1 01-10 18:35:44.372: E/AndroidRuntime(18378): java.lang.IllegalStateException: Must be called from main thread of process 01-10 18:35:44.372: E/AndroidRuntime(18378): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1373) 01-10 18:35:44.372: E/AndroidRuntime(18378): at android.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:437) 01-10 18:35:44.372: E/AndroidRuntime(18378): at android.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:454) 01-10 18:35:44.372: E/AndroidRuntime(18378): at android.app.Activity.onBackPressed(Activity.java:2134) 01-10 18:35:44.372: E/AndroidRuntime(18378): at com.vwap.friends.MygoBack(MyDialog.java:90) 01-10 18:35:44.372: E/AndroidRuntime(18378): at com.vwap.friends.MyDialog$3.run(MyDialog.java:83) 01-10 18:35:44.372: E/AndroidRuntime(18378): at java.util.Timer$TimerImpl.run(Timer.java:284)

  • I am completely unaware of the concept of fragments yet (i plan to work on that asap) and it looks like the error has something to do with it.

I don't know where to begin from. Do i start by reading about Fragments or can i quickly fix this and release my application?


Solution

  • try to Use runOnUiThread(Runnable action).

    Or

    you can Also Try with Handler:

    final Runnable YOURVIEW = new Runnable()
    {
        public void run() 
        {
            SampleMethod(); // Put your Method What you want change
            handler.postDelayed(this, timeout);
        }
    };
    
    handler.postDelayed(changeView, timeout);