[英]How to open main activity from two separate icons with different ui
I have an app that the main activity is including a map. 我有一个应用程序,其主要活动包括地图。 I want to create two icons on my home screen launcher, both of them will open the same main activity but with a different UI on the map. 我想在主屏幕启动器上创建两个图标,这两个图标都将打开相同的主要活动,但在地图上具有不同的UI。
For example : If I will press on icon A the app will be open with a fab on the map, and if I will press on icon B the app will be open without the fab on the map. 例如:如果我按图标A,则该应用程序将在地图上打开并显示晶圆厂;如果我按图标B,则该应用程序将在地图上显示无晶圆厂的情况下打开。
First you need to add second launcher intent to your manifest. 首先,您需要向清单中添加第二个启动器意图。
<activity
android:name=".yourpackage.MapActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data android:name="visibility" android:value="0"/>
</activity>
<activity-alias
android:name=".MapWithoutFabActivity"
android:targetActivity=".yourpackage.MapActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data android:name="visibility" android:value="1"/>
</activity-alias>
Next we need modify our map MapActivity for being ready to change visibility of fab button. 接下来,我们需要修改地图MapActivity以准备更改fab按钮的可见性。
public class MapActivity extends AppCompatActivity {
protected int fabVisibility = View.VISIBLE;
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Hope this method works.
Bundle bundle = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA).metaData;
int visibility = Integer.valueOf(bundle.getString("visibility"));
fab.setVisibility(visibility);
}
protected void onNewIntent(Intent intent) {
Bundle bundle = getPackageManager().getApplicationInfo(getPackageName(),
PackageManager.GET_META_DATA).metaData;
int visibility = Integer.valueOf(bundle.getString("visibility"));
fab.setVisibility(visibility);
}
Good luck there 祝你好运
Emre 埃姆雷
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.