Android deep linking - Back stack

前端 未结 3 714
长发绾君心
长发绾君心 2021-02-07 07:23

I am trying to implement deep linking in my Android application. I have been following this guide. I have an Android Activity that is started from and intent-filter in the Andro

相关标签:
3条回答
  • 2021-02-07 08:08

    i have been Working for App links and App indexing feature of Android with the basic of Deep Linking, I hope this is useful to index app pages and allow google To crawl the app as specified here Deep link Guide

    • The Major rule i studied in Deep linking and App indexing is to give First Click Free Experience to the User who launches from search or somewhere.and shouldn't contain any Login/Signup Page. However onBack button press event this must Go back to search results or originated place not to your Parent Activity. Source App indexing Best practices and Important

    And this best practice applies for App indexing API,since you have referred the deeplink link from App indexing Training site from Android Developer site.

    0 讨论(0)
  • 2021-02-07 08:10

    I came across the exact same problem. So, if you want your user to go to your parent activity, whenever they presses the UP button, you can define the parent activity in the AndroidManifest.xml and then programmatically control the up-navigation.

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        // Respond to the action bar's Up/Home button
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    
    @Override
    public void onBackPressed() {
        NavUtils.navigateUpFromSameTask(this);
    }
    

    You may do the same in all activities to constantly navigate the user up back to the home screen. Additionally, you may create the full back stack before navigating the user back. Read more in the following documentation.

    Providing Up Navigation

    A Straight Forward Solution

    You can simply check if the deep-linked activity has a back stack to go back in your app's task itself by calling isTaskRoot(). I'm not quite sure if it does have any caveats though.

    @Override
    public void onBackPressed() {
        if(isTaskRoot()) {
            Intent parentIntent = new Intent(this, ParentActivity.class);
            startActivity(parentIntent);
            finish();
        } else {
            super.onBackPressed();
        }
    }
    

    In this case, you don't really have to declare parent activities in the Android Manifest.

    0 讨论(0)
  • 2021-02-07 08:17

    Have you tried doing this,

    Intent intent = new Intent(this, MyActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addNextIntentWithParentStack(intent);
    stackBuilder.startActivities();
    

    You have to build your own App stack in case of deep links.

    0 讨论(0)
提交回复
热议问题