【问题标题】:Retrieve value from appA to appB using intents使用意图从应用程序到应用程序检索值
【发布时间】:2021-12-01 11:14:50
【问题描述】:

我有两个应用程序(appA 和 appB)。我想检索存储在appA sharedPreferences 中的单个值并在appB 中使用它。我可以使用意图来做到这一点吗?我只需要这样做一次(在第一次安装 appB 时)。

【问题讨论】:

    标签: java android android-intent


    【解决方案1】:

    您应该能够将.putextras() 添加到您的意图中,然后在appB 上使用getExtras() 获取它们(在检查它们是否存在之后)。

    查看此答案以供参考https://stackoverflow.com/a/5265952/10637400

    【讨论】:

      【解决方案2】:

      在appA中使用Intent启动appB

      // Launch appB in appA
      Intent intent = context.getPackageManager().getLaunchIntentForPackage(appB_PackageName);
      intent.putExtra("key","value");
      startActivity(intent);
      

      或者在 appB 中读取 sharedPreferences Android: Retrieving shared preferences of other application

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多