Bug 40456 - Calling off to another package with an Intent
Summary: Calling off to another package with an Intent
Status: VERIFIED ANSWERED
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 6.0.1 (C6SR1)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-04-15 21:43 UTC by joshbrown
Modified: 2016-06-14 12:33 UTC (History)
4 users (show)

Tags:
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:
Status:
VERIFIED ANSWERED

Description joshbrown 2016-04-15 21:43:07 UTC
Xamarin geniuses, 

I have created a small solution in Visual Studio that contains two Android projects. App1 calls to a specific activity in App2 with an intent when a button is clicked in App1. When that activity is started, by default, it will open up, then close abruptly. If I wait about 2 - 5 minutes, then try clicking the button again; the activity will start and open as expected. Once the activity opens successfully, the problem is "fixed". However, when I deploy the solution again, I encounter the problem again. So it seems as if it's related to a new deploy, and is consistent with it not working within 2 - 5 minutes of the new deploy.

I have tested the same code in Java (Android Studio), and it works correctly. I have also tested all of this on a Jelly Bean and Marshmallow emulator, and a KitKat phone. It works as expected while running the Android Studio code, and fails to run correctly in Xamarin (it runs the way I've explained above). 

Here is a link to my git hub that contains the code for what I explained above.

https://github.com/jbrown29/XamarinMultiProjectSolution


THANKS!!!!
Comment 1 Cody Beyer (MSFT) 2016-04-20 01:35:31 UTC
Cleaning up bug report

### Description

When calling a separate activity via intents, the new activity will close immediately upon launch

### Native Sample

https://www.dropbox.com/s/885zdtxwzf4jicc/josh%20brown%20-%20AndroidMultiPackageJava%20%281%29.zip?dl=0

### Xamarin Sample

https://www.dropbox.com/s/jhexctjb1zyh7iz/XamarinSample.zip?dl=0

### Steps to Reproduce

1. Download Xamarin Sample
2. Deploy App1 to Device
3. Click Button

### Expected Results

Activity two should launch and maintain launched

### Actual Results 

Activity two launches and then closes immediately 

### Versions

=== Xamarin Studio Business ===

Version 6.0 (build 4968)
Installation UUID: 882f6404-87ab-4833-9233-461dacb82d1e
Runtime:
	Mono 4.4.0 (mono-4.4.0-branch/a3fabf1) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 404000122

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.3 (10183.3)
Build 7D175

=== Xamarin.iOS ===

Version: 9.8.0.244 (Xamarin Business)
Hash: 977921b
Branch: cycle7
Build date: 2016-04-07 14:20:17-0400

=== Xamarin.Android ===

Version: 6.1.0.37 (Xamarin Business)
Android SDK: /Users/codybeyer/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.2   (API level 17)
		4.4   (API level 19)
		6.0   (API level 23)

SDK Tools Version: 25.1.1
SDK Platform Tools Version: 23.1.0
SDK Build Tools Version: 23.0.3

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Not Installed

=== Xamarin.Mac ===

Version: 2.8.0.244 (Xamarin Business)

=== Xamarin Inspector ===

Version: 0.7.1.0
Hash: 545e74c
Branch: master
Build date: Fri Apr  8 17:34:53 UTC 2016

=== Build Information ===

Release ID: 600004968
Git revision: ab7092ce63351276394f283e4f9c8646baf51fce
Build date: 2016-04-08 09:30:34-04
Xamarin addins: be0a0aef6ec8b075b4ba4690bd147d1e33c2abd7
Build lane: monodevelop-lion-cycle7

=== Operating System ===

Mac OS X 10.11.4
Darwin clb-mbp.local 15.4.0 Darwin Kernel Version 15.4.0
    Fri Feb 26 22:08:05 PST 2016
    root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Xamarin Inspector 0.7.1.0
Comment 2 Jonathan Pryor 2016-06-10 01:19:41 UTC
Sorry for the delay in replying. :-(

Unfortunately, I'm not able to reproduce the described behavior. What Android device do you see this 2-5 minute delay? What Android version?

That said, your project has App1.csproj referencing App2.csproj with %(ProjectReference.ReferenceOutputAssembly) set to True (the default value).

This can result in obscure and bizarre behavior when it comes to Android resources:

Background: https://forums.xamarin.com/discussion/comment/98092/#Comment_98092

Generally speaking, Don't Do That™.

In the case of your app, it means that Client.dll!Client.Resource.Layout.activity_two has the same value as App1.dll!Client.Resource.Layout.Main.

I don't think that the crash you describe would be caused by this *in your app*, but I can imagine scenarios in which that *could* cause a crash.

I would thus suggest removing the App2.csproj reference from App1.csproj and hardcode the value of ActivityTwo.Class into App1.MainActivityOne so that there is no cross-application-assembly dependency.

Finally, if the above suggestion still fails, could you please provide the `adb logcat` output when you see the app crash?
Comment 3 joshbrown 2016-06-10 14:03:02 UTC
Just to make sure there is no confusion, there is no "delay" after ActivityTwo is called from the button press event in MainActivityOne. It initially closes(crashes) and shows MainActivityOne when the button is clicked in MainActivityOne, as if ActivityTwo was never called via Intent. This all happens on a new app deploy.

It's worth noting that this doesn't occur when the app has been for over 5 minutes.

I've updated to the latest stable version of Xamarin, and can still reproduce this problem with Android 4.4.3 physical device and an Android 6.0 Emulator.


My Android Device Logging output:

06-10 08:46:37.286 D/Intent  ( 2135): ActivityTwo Started
06-10 08:46:37.286 I/ActivityManager( 2135): Timeline: Activity_launch_request id:Client.Client time:34546927
06-10 08:46:37.286 I/ActivityManager(  806): START u0 {act=ActivityTwo cat=[android.intent.category.DEFAULT] cmp=Client.Client/md5321d0225785f1727d20b8e45a7be13fd.ActivityTwo} from pid 2135
06-10 08:46:37.306 D/dalvikvm( 2249): Late-enabling CheckJNI
06-10 08:46:37.316 I/ActivityManager(  806): Start proc Client.Client for activity Client.Client/md5321d0225785f1727d20b8e45a7be13fd.ActivityTwo: pid=2249 uid=10190 gids={50190, 3003, 1028}
06-10 08:46:37.376 D/PhoneStatusBar( 9537): hiding the MENU button
06-10 08:46:37.386 D/dalvikvm( 2249): Trying to load lib /data/app-lib/Client.Client-2/libmonodroid.so 0x42215348
06-10 08:46:37.396 D/dalvikvm( 2249): Added shared lib /data/app-lib/Client.Client-2/libmonodroid.so 0x42215348
06-10 08:46:37.396 W/monodroid( 2249): Using override path: /data/data/Client.Client/files/.__override__
06-10 08:46:37.396 W/monodroid( 2249): Using override path: /storage/sdcard0/Android/data/Client.Client/files/.__override__
06-10 08:46:37.396 W/monodroid( 2249): Trying to load sgen from: /data/data/Client.Client/files/.__override__/libmonosgen-2.0.so
06-10 08:46:37.396 W/monodroid( 2249): Trying to load sgen from: /storage/sdcard0/Android/data/Client.Client/files/.__override__/libmonosgen-2.0.so
06-10 08:46:37.406 W/monodroid( 2249): Trying to load sgen from: /data/app-lib/Client.Client-2/libmonosgen-2.0.so
06-10 08:46:37.406 W/monodroid( 2249): Trying to load sgen from: /data/data/Client.Client/files/.__override__/links/libmonosgen-2.0.so
06-10 08:46:37.406 W/monodroid-debug( 2249): Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=127.0.0.1:8905,server=y,embedding=1
06-10 08:46:37.406 W/monodroid-debug( 2249): Accepted stdout connection: -1
06-10 08:46:37.406 F/monodroid-debug( 2249): Error accepting stdout and stderr (127.0.0.1:8906): Address already in use
06-10 08:46:37.436 D/Zygote  (  166): Process 2249 exited cleanly (3)
06-10 08:46:37.436 I/ActivityManager(  806): Process Client.Client (pid 2249) has died.
06-10 08:46:37.446 D/dalvikvm( 2269): Late-enabling CheckJNI
06-10 08:46:37.446 I/ActivityManager(  806): Start proc Client.Client for activity Client.Client/md5321d0225785f1727d20b8e45a7be13fd.ActivityTwo: pid=2269 uid=10190 gids={50190, 3003, 1028}
06-10 08:46:37.487 D/dalvikvm( 2269): Trying to load lib /data/app-lib/Client.Client-2/libmonodroid.so 0x422161d0
06-10 08:46:37.487 D/dalvikvm( 2269): Added shared lib /data/app-lib/Client.Client-2/libmonodroid.so 0x422161d0
06-10 08:46:37.497 W/monodroid( 2269): Using override path: /data/data/Client.Client/files/.__override__
06-10 08:46:37.497 W/monodroid( 2269): Using override path: /storage/sdcard0/Android/data/Client.Client/files/.__override__
06-10 08:46:37.497 W/monodroid( 2269): Trying to load sgen from: /data/data/Client.Client/files/.__override__/libmonosgen-2.0.so
06-10 08:46:37.497 W/monodroid( 2269): Trying to load sgen from: /storage/sdcard0/Android/data/Client.Client/files/.__override__/libmonosgen-2.0.so
06-10 08:46:37.497 W/monodroid( 2269): Trying to load sgen from: /data/app-lib/Client.Client-2/libmonosgen-2.0.so
06-10 08:46:37.497 W/monodroid( 2269): Trying to load sgen from: /data/data/Client.Client/files/.__override__/links/libmonosgen-2.0.so
06-10 08:46:37.497 W/monodroid-debug( 2269): Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=127.0.0.1:8905,server=y,embedding=1
06-10 08:46:37.497 W/monodroid-debug( 2269): Accepted stdout connection: -1
06-10 08:46:37.497 F/monodroid-debug( 2269): Error accepting stdout and stderr (127.0.0.1:8906): Address already in use
06-10 08:46:37.517 D/Zygote  (  166): Process 2269 exited cleanly (3)
06-10 08:46:37.517 I/ActivityManager(  806): Process Client.Client (pid 2269) has died.
06-10 08:46:37.537 D/dalvikvm( 2283): Late-enabling CheckJNI
06-10 08:46:37.537 I/ActivityManager(  806): Start proc Client.Client for activity Client.Client/md5321d0225785f1727d20b8e45a7be13fd.ActivityTwo: pid=2283 uid=10190 gids={50190, 3003, 1028}
06-10 08:46:37.577 D/dalvikvm( 2283): Trying to load lib /data/app-lib/Client.Client-2/libmonodroid.so 0x422170e8
06-10 08:46:37.577 D/dalvikvm( 2283): Added shared lib /data/app-lib/Client.Client-2/libmonodroid.so 0x422170e8
06-10 08:46:37.587 W/monodroid( 2283): Using override path: /data/data/Client.Client/files/.__override__
06-10 08:46:37.587 W/monodroid( 2283): Using override path: /storage/sdcard0/Android/data/Client.Client/files/.__override__
06-10 08:46:37.587 W/monodroid( 2283): Trying to load sgen from: /data/data/Client.Client/files/.__override__/libmonosgen-2.0.so
06-10 08:46:37.587 W/monodroid( 2283): Trying to load sgen from: /storage/sdcard0/Android/data/Client.Client/files/.__override__/libmonosgen-2.0.so
06-10 08:46:37.587 W/monodroid( 2283): Trying to load sgen from: /data/app-lib/Client.Client-2/libmonosgen-2.0.so
06-10 08:46:37.587 W/monodroid( 2283): Trying to load sgen from: /data/data/Client.Client/files/.__override__/links/libmonosgen-2.0.so
06-10 08:46:37.587 W/monodroid-debug( 2283): Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=127.0.0.1:8905,server=y,embedding=1
06-10 08:46:37.587 W/monodroid-debug( 2283): Accepted stdout connection: -1
06-10 08:46:37.587 F/monodroid-debug( 2283): Error accepting stdout and stderr (127.0.0.1:8906): Address already in use
06-10 08:46:37.607 D/Zygote  (  166): Process 2283 exited cleanly (3)
06-10 08:46:37.607 I/ActivityManager(  806): Process Client.Client (pid 2283) has died.
06-10 08:46:37.607 W/ActivityManager(  806): Force removing ActivityRecord{423ca158 u0 Client.Client/md5321d0225785f1727d20b8e45a7be13fd.ActivityTwo t83}: app died, no saved state
06-10 08:46:37.617 D/PhoneStatusBar( 9537): hiding the MENU button
06-10 08:46:37.627 E/HAL     ( 2135): hw_get_module_by_class path = /system/lib/hw/gralloc.msm8960.so
06-10 08:46:37.627 W/InputMethodManagerService(  806): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@423b0390 attribute=null, token = android.os.BinderProxy@423ec4b0
06-10 08:46:37.657 I/ActivityManager( 2135): Timeline: Activity_idle id: android.os.BinderProxy@42211350 time:34547299
06-10 08:46:37.957 I/ActivityManager(  806): Timeline: Activity_windows_visible id: ActivityRecord{42347c10 u0 App1.App1/md5579855c995bdb073d8182511e793544c.MainActivityOne t83} time:34547593
Comment 4 Jonathan Pryor 2016-06-11 15:08:02 UTC
Aside: If you prefix a line with `> `, bugzilla will disable line wrapping, making for more readable output.

> 06-10 08:46:37.406 W/monodroid-debug( 2249): Accepted stdout connection: -1
> 06-10 08:46:37.406 F/monodroid-debug( 2249): Error accepting stdout and stderr (127.0.0.1:8906): Address already in use
...
> 06-10 08:46:37.587 W/monodroid-debug( 2283): Accepted stdout connection: -1
> 06-10 08:46:37.587 F/monodroid-debug( 2283): Error accepting stdout and stderr (127.0.0.1:8906): Address already in use

I believe the "problem" is that you're debugging the app.

Please try to repro *without* using the debugger, either by launching from the device or by using Run > Start Without Debugging.

Background; at present, debugging works by setting an Android system property ("debug.mono.extra") which tells the app to connect to a certain port. Unfortunately, this system property is *global to the device*, which means only a single process at a time can be debugged.

Furthermore, if the system property is set but the app can't attach to the debug ports, it will exit, with the above quoted error messages.

The result is thus what you observe: you launch the app, the initial app attaches to the debugger, you tap a button, and the process it launches "crashes" because the new process *can't* attach to the debugger.

On the plus side, you don't need to wait 5 minutes. We have a timeout of 30 seconds, so waiting 30 seconds to a minute should suffice. Or don't use the debugger in this instance, in which case the debug.mono.extra system property won't be set, and nothing will attempt to connect to the debugger.
Comment 5 joshbrown 2016-06-14 12:33:20 UTC
Jonathan,

I disabled the debugger, and everything worked correctly as you described.
Thanks for your insightfulness and thoroughness!

Thanks,
Josh Brown