简体   繁体   English

如何从两个具有不同ui的单独图标中打开主要活动

[英]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.

相关问题 如何从选项卡中的两个不同片段获取数据到主要活动 - How to get data from two different fragments in tabs to main activity 如何将来自单独的AsyncTask内部类的两个结果传递给主活动中的相同方法? - How do I pass two results from separate AsyncTask inner classes to the same method in the main activity? 如何从通知中打开不是主要活动 - How open not main activity from Notification 如何从 Kotlin 的主要活动中打开多个活动? - How to open more than activity from Main Activity in Kotlin? 如何使用主活动中的按钮增加其他活动中的TextView值? - How to increment a TextView value in a different activity with a button from the Main Activity? 如何从不同的Activity获取主要启动活动的Intent? - How to get Intent of main launch Activity from a different Activity? 从主要活动中打开MultipleFragment - Open MultipleFragment from main activity 如何在单独的活动中从RecyclerView打开图像? - How can I open an image from a RecyclerView in a separate activity? 如何从Main Activity中访问片段及其关联的UI元素 - How to access Fragments and their associated UI elements from Main Activity 如何打开 WebView 或从自定义选项卡中分离 Chrome 活动 - How to open WebView or separate Chrome activity from Custom Tabs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM