While playing with MvvmCross I encountered a situation, where an Activity cannot be started if it has been previously started, if one uses ActivityFlags.NewTask flags on an intent, which is used to start an activity.
I've demonstrated this in code here: https://github.com/skyflyer/XamarinAndroidNewTaskIntentFlag
I've also added an equivalent project in Java (developed using Eclipse), which works as expected.
The situation is as follows:
Start ActivityA, then from there (say on a button click) start ActivityB (with flag set to NewTask), then in ActivityB, start ActivityA with intent with flags set to NewTask. The ActivityA will not start, if you're using Xamarin.Android. I'm using XamarinStudio (alpha channel):
Version 4.3.1 (build 5)
Installation UUID: c8c12daf-0622-4167-a85a-cf0db7a634b2
Mono 3.2.6 ((no/9b58377)
GTK+ 2.24.23 theme: Raleigh
Package version: 302060000
Version: 4.12.0 (Trial Edition)
Android SDK: /Users/miha/Library/Developer/Xamarin/android-sdk-mac_x86
Supported Android versions:
2.1 (API level 7)
2.2 (API level 8)
2.3 (API level 10)
3.1 (API level 12)
4.0 (API level 14)
4.0.3 (API level 15)
4.4 (API level 19)
Java SDK: /usr
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b12)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
I have run the attached project from link: https://github.com/skyflyer/XamarinAndroidNewTaskIntentFlag on following builds:
X.S 4.3.1(build 5)
Application displaying me button 'First' on First one page when launch on device. After clicking on this button it redirects to Second one page which shows me button 'Go to main' . When I click on this button to back on First page it does not redirect to First one page. This is the Application Output for the same: https://gist.github.com/saurabh360/34a7b3cd75edaec91949
I am not sure is is it same Issue which Miha facing or is it something different.
this is also the behaviour I'm seeing and it is wrong, IMHO. When clicking the "Go to main" you should see the First page again. If you comment the intent.setFlags lines in both activities, you will see the how it is supposed to work.
Whilst I think the beahavior we are seeing is stupid it does not look like a xamarin thing as I repro'd it in vanilla Android.
I have a workaround for this in MVVM Cross if you are interested
Pat, no need for a workaround, but thanks. Interesting that you've been able to repro it with vanilla Android, as I have not (I've shared a working eclipse project (see above)).
I can confirm this bug as a Xamarin (but not Android) but.
I've attached a zip with two samples - on in Xamarin.Android that shows the error. Another project (using Kotlin) where things seem to work correctly.
Created attachment 23222 [details]
Two sample projects to help confirm the bug.