Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Launch another app

MagnusKronaMagnusKrona SEMember ✭✭

Hi

I have the following code to open up another installed app on the device.

Intent launchIntent = Application.Context.PackageManager.GetLaunchIntentForPackage("com.xxxxxxx.xxxxxxx");
Application.Context.StartActivity(launchIntent);

The other app/activity is opened, but it is opened in the same "context" as the current app. It is not opening as a "standalone" app.

What can I do to make sure the app is opened as standalone?

/Magnus

Tagged:

Best Answer

Answers

  • AlchemySolutionsAlchemySolutions USMember

    Intent intent = new Intent();
    intent =PackageManager.GetLaunchIntentForPackage("com.whatsapp");
    StartActivity(intent);

    I have tried above code in my custom renderer, but in PackageManager i'm getting ERROR i.e.

    Java.Lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
    at Android.Runtime.JNIEnv.CallNonvirtualObjectMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod) [0x00084] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:596
    at Android.Content.ContextWrapper.get_PackageManager () [0x0005f] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Content.ContextWrapper.cs:562
    at App1.Droid.OpenAppRenderer.openApplication (System.String appname)

    kindly provide any solution .

    Thx in advance.

Sign In or Register to comment.