我已经阅读了以下帖子
但是我无法弄清楚如何进行深层链接,以便加载特定的屏幕。这是我的用例。我已经设置了具有意图过滤器的深层链接活动处理程序,以按以下步骤深层链接到特定活动。对于以下深层链接
adb -e shell启动-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管理。
我该怎么办?