Did you want to make a browser with plugins, a program with themes, a game with addons or some other modular Android application? But how to do that? I will tell you how to make a simple application that will receive text from modules.<intent-filter> <action> name parameter will have a value of type my.app.GET_DATA, and the application will send start requests using startActivity (startActivityForResult) and startIntentSender (startIntentSenderForResult). I want to remind that one Activity can have several <intent-filter> tags. // "mod.ul.ed.MODULES" - action intent-filter' Intent call = new Intent("mod.ul.ed.MODULES"); startActivity(call); After calling startActivity, Android will ask the user which module to open and upon selection (you can assign a default module) will open. Intent call = new Intent("mod.ul.ed.MODULES"); // mod.ule.first - // mod.ule.first.ActivityMain - Activity call.setClassName("mod.ule.first", "mod.ule.first.MainActivity"); startActivity(call); You can also pass parameters to the module, see the description of the Intent class for this. Intent call = new Intent("mod.ul.ed.GET_TEXT"); // , call.setClassName("mod.ule.first", "mod.ule.first.MainActivity"); IntentSender sender = PendingIntent.getActivity(getApplicationContext(), 1, call, 0).getIntentSender(); try { startIntentSenderForResult(sender, 1, call, 0, 0, 0); } catch (SendIntentException e) { } If you use startActivityForResult, then the user will be able to see the flashing of another window (Activity). // Activity, action = "mod.ul.ed.MODULES" Intent intent = new Intent("mod.ul.ed.MODULES"); // Activity List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, 0); <intent-filter> <action android:name="mod.ul.ed.GET_TEXT" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> // action if(getIntent().getAction().equals("mod.ul.ed.GET_TEXT")) { // Intent data = new Intent(); data.putExtra("text", "This is first module"); setResult(RESULT_OK, data); // finish(); // Activity return; // } Source: https://habr.com/ru/post/123306/
All Articles