java - Real Time Scenarios to use singleton class in android -
i know singleton class. want know real time scenarios use singleton class in android . can give me examples in android use , benefits of scenario..
two real scenarios
- extend application class , use it's instance access app context within class
- sql database idea singleton class
here example of app usage
import android.app.application; public class myapplication extends application { private static myapplication instance = null; public static myapplication getinstance() { return instance; } @override public void oncreate() { if (instance == null) { instance = this; } } }
access string in r
public class dummyclass { private void getappstring(){ string r = myapplication.getinstance().getstring(r.string.app_name); } }
Comments
Post a Comment