I have xamarin.android project Client1 & 1 CommonApp project(within the same solution) which have all common code. From Client1 project I need to start CommonApp, my code to do so in Client1 app
public class MainActivity : AppCompatActivity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); FindViewById<Button>(Resource.Id.btn1).Click += delegate { //Starting CommonApp project StartActivity(new Intent(Application.Context, typeof(CommonApp.MainActivity))); }; } } Below 1 is CommonApp MainActivity where debugger point going but not starting new activity but the same activity getting added in backstack when i am pressing physical back button it is getting removed.
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); //This is CommonApp SetContentView(Resource.Layout.activity_main); } CommonApp activity_main have
<TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="This is CommonApp"> </TextView> Description: I have I solution with 2 android app. 1 CommonApp & 2nd Client1. Cleint1 is startup projet having .dll of type CommonApp. From Cleint1 app I am starting CommonApp by importing CommonApp namespace. I can have many project Client1, Client2, Client3...etc with their own icons, app name, splash screen & google-service.json. When I set Client2 on startup it becomes Client2 project & all common code available in CommonApp.
Requirement: Here
App Log
Updated screenshot:
3 Answers
Answers 1
If you know the package name of the another application than you can achieve your goal by calling intent.
String appName = "appName"; String packageName = "package.of.another.application"; openApp(context, appName, packageName); public static void openApp(Context context, String appName, String packageName) { if (isAppInstalled(context, packageName)) if (isAppEnabled(context, packageName)) context.startActivity(context.getPackageManager().getLaunchIntentForPackage(packageName)); else Toast.makeText(context, appName + " app is not enabled.", Toast.LENGTH_SHORT).show(); else Toast.makeText(context, appName + " app is not installed.", Toast.LENGTH_SHORT).show(); } private static boolean isAppInstalled(Context context, String packageName) { PackageManager pm = context.getPackageManager(); try { pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); return true; } catch (PackageManager.NameNotFoundException ignored) { } return false; } private static boolean isAppEnabled(Context context, String packageName) { boolean appStatus = false; try { ApplicationInfo ai = context.getPackageManager().getApplicationInfo(packageName, 0); if (ai != null) { appStatus = ai.enabled; } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return appStatus; } Answers 2
Make sure your common app is installed are not. if already installed you can try this
Intent intent = PackageManager.GetLaunchIntentForPackage("Com.CommonAPP.CommonAPP"); if (intent != null) { StartActivity(intent); } Hope this will helps you.
Answers 3
I think that the CommonApp Activity is actually started (as shown by the debugger) but it doesn't use the correct layout file. Both MainActivitys (the one from CommonApp and the one from Client1) use a layout named activity_main. So both projects contain a activity_main.xml file and it seems that one (from Client1 project) overwrite the other.
There is no namespace for resources, you need to rename the layouts (and any other resources that you want to remain distinct) to avoid the collision. You could add a prefix, e.g. common_activity_main and client_activity_main


0 comments:
Post a Comment