I'm having a very strange problem with my app, which consists of an Activity and 2 Fragments (android.support.v4.app.Fragment).
The problem is when I rotate my tablet : the app crashes right away.
A few days before, everything was working fine, but I had to change packages name, that threw a few errors but I manage to correct them. Problem appeared right after that, but I just can't find where is the error. Here is the Logcat I get right after the app is destroyed, restarted, resumed and created :
10-08 17:00:14.930: D/dalvikvm(18155): GC_CONCURRENT freed 394K, 8% free 7792K/8455K, paused 1ms+4ms
10-08 17:00:14.930: D/AndroidRuntime(18155): Shutting down VM
10-08 17:00:14.930: W/dalvikvm(18155): threadid=1: thread exiting with uncaught exception (group=0x40bee1f8)
10-08 17:00:14.938: E/AndroidRuntime(18155): FATAL EXCEPTION: main
10-08 17:00:14.938: E/AndroidRuntime(18155): java.lang.IllegalStateException: No activity
10-08 17:00:14.938: E/AndroidRuntime(18155): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1070)
10-08 17:00:14.938: E/AndroidRuntime(18155): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1065)
10-08 17:00:14.938: E/AndroidRuntime(18155): at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:1854)
10-08 17:00:14.938: E/AndroidRuntime(18155): at android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:431)
10-08 17:00:14.938: E/AndroidRuntime(18155): at android.support.v4.app.FragmentActivity$1.handleMessage(FragmentActivity.java:90)
10-08 17:00:14.938: E/AndroidRuntime(18155): at android.os.Handler.dispatchMessage(Handler.java:99)
10-08 17:00:14.938: E/AndroidRuntime(18155): at android.os.Looper.loop(Looper.java:137)
10-08 17:00:14.938: E/AndroidRuntime(18155): at android.app.ActivityThread.main(ActivityThread.java:4514)
10-08 17:00:14.938: E/AndroidRuntime(18155): at java.lang.reflect.Method.invokeNative(Native Method)
10-08 17:00:14.938: E/AndroidRuntime(18155): at java.lang.reflect.Method.invoke(Method.java:511)
10-08 17:00:14.938: E/AndroidRuntime(18155): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
10-08 17:00:14.938: E/AndroidRuntime(18155): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
10-08 17:00:14.938: E/AndroidRuntime(18155): at dalvik.system.NativeStart.main(Native Method)
The problem comes from FragmentManager but why, I don't know, as I don't have any details. I tried a solution i found on this site to get more info, by catching uncaught exception, but the result i got was the same Logcat repeated again and again until some kind of out of memory error happened(too many strings in the logcat).
My Activity's layout is the following one, it works well with android lifecycle, but not with screen rotation :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id = "@+id/mainview"
tools:context=".MyActivity" >
<fragment
android:id="@+id/missionFragment"
android:layout_width="350dip"
android:layout_height="match_parent"
android:layout_marginTop="?android:attr/actionBarSize"
android:name="com.xxx.xxx.MissionFragment">
</fragment>
<fragment
android:id="@+id/mapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.xxx.xxx.MapFragment">
</fragment>
</LinearLayout>
Manifest is right there :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.xxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:icon="@drawable/logo"
android:label="@string/app_name" >
<activity
android:name=".MySIGActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
If anyone has any idea on where would the error come, on which android lifecycle method, that would be welcomed!
Thanks.
UPDATE 1.1: Here is onCreate method of my main Activity :
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = getApplicationContext();
currentEtape = 1;
// Set up the action bar.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
// Désactiver l'affichage du titre de l'application et son icône
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
setContentView(R.layout.main);
SharedPreferences prefs = getPreferences(0);
trackingGPS = prefs.getBoolean("trackingGPS", false);
if(trackingGPS){
TextView viewTrackingActive = (TextView)findViewById(R.id.textview_notif_tracking);
viewTrackingActive.setText(this.getString(R.string.active));
viewTrackingActive.setTextColor(Color.parseColor("#99CC00"));
}
else{
TextView viewTrackingDesactive = (TextView)findViewById(R.id.textview_notif_tracking);
viewTrackingDesactive.setText(this.getString(R.string.desactive));
viewTrackingDesactive.setTextColor(Color.parseColor("#CC0000"));
}
// No interaction with Fragment or Activity classes in these methods
instanciateLayersDialog();
instanciateBasemapDialog();
}
And onResume method :
public void onResume(){
super.onResume();
SharedPreferences prefs = getPreferences(0);
trackingGPS = prefs.getBoolean("trackingGPS", false);
System.out.println("activity resume");
}
I'm not sure if this answers the problem of the original poster, but I had this same problem when I had an onPause() method in my main Activity that looked like this:
@Override
public void onPause() {
super.onResume();
...do other stuff...
}
As you can see, it was just a typo, but it took me a while to track it down since the error message "No Activity" was so vague. ("super.onResume" should have been "super.onPause", if it's not obvious.)
If this is not your exact issue, I believe it had something to do with the original Fragment not getting destroyed (by the proper onPause() call in my case).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With