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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -