Shailendra Sachan
Shailendra Sachan

Reputation: 165

Deep Link Url open activity after logging the user

How to Open Deep linked Url activity after logging in (Android)?

Let's us suppose this is the deep linked URL: www.xyz.com/articles

When user will click on this link it will open MyArticlesActivity

But what I want is to first allow user to log in and then open this activity.

Upvotes: 6

Views: 5054

Answers (3)

Chetan Joshi
Chetan Joshi

Reputation: 5711

You need to maintain Login Session for your application, by making Database or SharedPrefrence to hold login details and when your Activity triggers from Deep Link Url you should Check the session in OnCreate() for the First time and if the application is already running then put same conditions in OnNewIntent() method in your Activity class.

OnNewIntent() method is triggered when the targeted Activity is already running.

Upvotes: 1

Kavach Chandra
Kavach Chandra

Reputation: 770

Check out the official android documentation on this link :

https://developer.android.com/training/app-indexing/deep-linking.html

Just put a check for login the in the activity before reading data from intent. Something like:

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Intent intent = getIntent();
String action = intent.getAction();
 if(isLoggedIn){    //login check
 Uri data = intent.getData();
 //method call for rest of the activity functions.
 } else {
//Alternate method call or prompt for user login.
  }

}

Upvotes: 3

Anil
Anil

Reputation: 1087

For That Create Separate Login Activity and use deep linking in that activity once the user logged in pass data from that activity to MyArticlesActivity

Upvotes: 0

Related Questions