Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add methods that I often use to android studio?

For example,

public void show_message(String message){
    Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}

I want this method add auto Activity.java when create new activity or java class.

I want to save different methods like this and include it in the my project quickly where it is needed.

like image 560
Halil ONCEN Avatar asked Dec 23 '22 15:12

Halil ONCEN


2 Answers

What you should do is create a BaseActivity and make your activity extend this BaseActivity. Add all the default methods in this activity so you can use them everywhere. You can refer this Github project for reference. It uses MVP.

Here is direct link to BaseActivity.

like image 153
Nilesh Deokar Avatar answered Jan 04 '23 23:01

Nilesh Deokar


You just need to make a Common Utilities class. Just copy and paste the class in whatever project you are using it. Just make its method access specifiers as public staic so that you can easily access it. For e.g.

CommonUtilities.showToastMessage(String text);
like image 23
Rahul Khurana Avatar answered Jan 04 '23 22:01

Rahul Khurana