我已阅读以下帖子
但我无法弄清楚如何进行深度链接以加载特定的屏幕。这是我的用例。我已经设置了一个带有意图过滤器的深层链接活动处理程序,以深层链接到特定活动,如下所示。对于以下深层链接
adb -e shell am start -a "android.intent.action.VIEW" -d "myapp://link?nav=user.settings.push\&preference=notifications"
我有我的活动来处理传入的深层链接,如下所示。
Uri ur = getIntent().getData();
String preference = uri.getQueryParameter("preference");
Intent processorIntent = new Intent(this, SettingsActivity.class);
processorIntent.putExtra("preference", preference);
. . . . other attributes are added as such ONE_SHOT_FLAG etc.
startActivity(processorIntent);
在我的 SettingsActivity 中,我有以下内容
public class SettingsActivity extends AppCompatActivity
implements PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
final FragmentManager fragmentManager = getSupportFragmentManager();
if (fragmentManager != null)
{
String settingsPreference =
getIntent().getStringExtra("preference");
final Fragment fragment
if (preference != null) {
fragment = new NotificationPreferencesFragment();
} else {
fragment = new RootPreferences();
}
fragment.setArguments(savedInstanceState);
fragmentManager.beginTransaction()
.add(R.id.master_container, fragment, "root_fragment")
.commit();
}
}
}
RootPreferenceFragment
这是我定义我的偏好的地方
public class RootPreferencesFragment extends PreferenceFragmentCompat
{
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey)
{
final Activity activity = getActivity();
// Initialize view models
final ViewModelProvider viewModelProvider = ViewModelProviders.of(activity, viewModelProviderFactory);
RootViewModel rootViewModel = viewModelProvider.get(RootViewModel.class);
. . . . Initialise Other Preferences . . . .
// Notifications
final Preference notificationsPreference = preferencesFactory.create(
accountCategory,
Preference.class,
RootViewModel.ACCOUNT_NOTIFICATIONS_PREFERENCE_KEY,
R.string.PushNotifications,
RootViewModel.ACCOUNT_CATEGORY_KEY);
notificationsPreference.setFragment(NotificationPreferencesFragment.class.getName());
// I want to deep link into this one.
}
}
这就是我的屏幕的样子。我能够进入通知屏幕,但我无法通过后退按钮进入此屏幕。此屏幕由 RootPreferencesFragment 管理。
我该怎么做?