Bug 17350 - IllegalStateException: No activity when use ActionBar from Appcompat in ART.
Summary: IllegalStateException: No activity when use ActionBar from Appcompat in ART.
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.10.2
Hardware: All Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL: https://components.xamarin.com/view/x...
Depends on:
Reported: 2014-01-21 12:36 UTC by BOOM
Modified: 2014-02-11 20:16 UTC (History)
3 users (show)

Tags: appcompat, suport labrary, art
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description BOOM 2014-01-21 12:36:47 UTC

 java.lang.RuntimeException: Unable to start activity ComponentInfo{Bigrocket.Android/bigrocket.android.MainActivity}: java.lang.IllegalStateException: No activity
    [AndroidRuntime]    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
    [AndroidRuntime]    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2248)
    [AndroidRuntime]    at android.app.ActivityThread.access$800(ActivityThread.java:138)
    [AndroidRuntime]    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
    [AndroidRuntime]    at android.os.Handler.dispatchMessage(Handler.java:102)
    [AndroidRuntime]    at android.os.Looper.loop(Looper.java:136)
    [AndroidRuntime]    at android.app.ActivityThread.main(ActivityThread.java:5050)
    [AndroidRuntime]    at java.lang.reflect.Method.invoke(Native Method)
    [AndroidRuntime]    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    [AndroidRuntime]    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    [AndroidRuntime] Caused by: java.lang.IllegalStateException: No activity
    [AndroidRuntime]    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1091)
    [AndroidRuntime]    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
    [AndroidRuntime]    at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1877)
    [AndroidRuntime]    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:552)
    [AndroidRuntime]    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
    [AndroidRuntime]    at android.app.Activity.performStart(Activity.java:5251)
    [AndroidRuntime]    at android.app.ActivityThread.performLat our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);


[Activity (Label = "Test", Icon = "@drawable/Icon", Theme = "@style/Theme.AppCompat.Light", MainLauncher = true)]
    public class MainActivity : ActionBarActivity
        protected override void OnCreate (Bundle bundle)
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.Main);

When use ART runtime application crashed with "No Activity" exception. When use Dalvik runtime all work stable.

I tried connect Appcompat from component and as binding library.
Comment 1 Jonathan Pryor 2014-01-21 12:53:07 UTC
If it works under Dalvik and fails under ART, that's not a sign of a Xamarin.Android bug, that's a sign of an ART bug. It's not like ART can be presumed to be bug-free, e.g.:


(Yes, fixed now, but it _wasn't_ fixed until I spent a week creating a repro for them, and that fix hasn't been released either. You can thus safely assume that ALL KitKat+ART devices have the above bug.)
Comment 2 Adam Patridge 2014-02-10 16:47:21 UTC
Here are a few other situations where this can pop up. I hope you don't mind me adding them for SEO benefits, but with a few more details, I'm hoping to make this the natural destination for people. I fully expect the problem to go away as ART evolves.

These additional situations all seem to be a result of the `Activity` being lost, what seems to be happening in the original bug, but manifesting themselves in different symptoms. These issues were seen on a Nexus 7 (2013) under Android v4.4.2 with the app built with Xamarin.Android 4.12.0 (obviously switched from Dalvik runtime to ART).

The first two situations are also using the v7 AppCompat Support Library to add some navigation stuff. When adding ActionBar Tabs, as soon as this line is hit in `OnCreate`, it blows up.

    SupportActionBar.NavigationMode = ActionBar.NavigationModeTabs;

Resulting in a Java.Lang.NullPointerException: "Attempt to invoke virtual method 'android.support.v7.app.ActionBar android.support.v7.app.ActionBarActivityDelegate.getSupportActionBar()' on a null object reference".

Second, when adding a Navigation Drawer, another null pointer issue:

    someDrawerToggle = new ActionBarDrawerToggle (this, someDrawerLayout, Resource.Drawable.ic_drawer, Resource.String.drawer_open, Resource.String.drawer_close);
Resulting in a Java.Lang.NullPointerException: "Attempt to invoke virtual method 'android.support.v4.app.ActionBarDrawerToggle$Delegate android.support.v7.app.ActionBarActivityDelegate.getDrawerToggleDelegate()' on a null object reference"

Finally, this can also happen in when committing a `FragmentTransaction` as well from an `OnResume`.

    var ft = SupportFragmentManager.BeginTransaction();
    ft.Replace(Resource.Id.some_view_id, newFragment)
    ft.Commit(); // Blows up here.

Resulting in a Java.Lang.IllegalStateException: "Activity has been destroyed."
Comment 3 Jonathan Pryor 2014-02-11 17:19:21 UTC
This is actually probably a bug in how Xamarin.Android was performing non-virtual method invocation; see Bug #17630.
Comment 4 Adam Patridge 2014-02-11 18:25:26 UTC
When you refer to monodroid-4.12-series in that closed bug comment, does that cover 4.12.0 or will it show up in something later than that? I had the issues above using 4.12.0, the latest on Alpha at the time.
Comment 5 Jonathan Pryor 2014-02-11 20:16:55 UTC
It will be included in an updated 4.12.0 beta before it is promoted to stable.