Agent K
Agent K

Reputation: 351

How to share common code among multiple activities? Please, this is not a repeated question

Actually I'm trying to create an app it has Navigation Drawer and Google Sign In for which I also need to add auth code every where.

I wanted to know is there any way of putting all the navigation drawer code somewhere else (say in different class file) and then calling the code in the different activities?

As copy pasting the same thing again and again is sometime irritating.

Please help.

Thanks.

Upvotes: 0

Views: 91

Answers (2)

nebinec402
nebinec402

Reputation: 9

The process is simple, create classes and pass the data as a parameter

Upvotes: 0

user13651827
user13651827

Reputation:

You can do it very simply.

But this is not a good approach that you sign in with google in every item of navigation drawer. If you sign in user on first screen and then access that user wherever you want without doing unwanted things in code.

But Still you want solution

Solution

you should make a google sign in method in a class with parameter Context. Access it wherever you want from that class provides sign in method.

Library

you can do it very simply by library from github:

Google Sign in library

Upvotes: 3

Related Questions