【发布时间】:2021-12-01 11:14:50
【问题描述】:
我有两个应用程序(appA 和 appB)。我想检索存储在appA sharedPreferences 中的单个值并在appB 中使用它。我可以使用意图来做到这一点吗?我只需要这样做一次(在第一次安装 appB 时)。
【问题讨论】:
标签: java android android-intent
我有两个应用程序(appA 和 appB)。我想检索存储在appA sharedPreferences 中的单个值并在appB 中使用它。我可以使用意图来做到这一点吗?我只需要这样做一次(在第一次安装 appB 时)。
【问题讨论】:
标签: java android android-intent
您应该能够将.putextras() 添加到您的意图中,然后在appB 上使用getExtras() 获取它们(在检查它们是否存在之后)。
【讨论】:
在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
【讨论】: