Skip to content

Instantly share code, notes, and snippets.

@parahall
Last active December 30, 2015 07:46
Show Gist options
  • Save parahall/eadd11ec6b1a64ad3f70 to your computer and use it in GitHub Desktop.
Save parahall/eadd11ec6b1a64ad3f70 to your computer and use it in GitHub Desktop.
Android Academy Weekly Quizz
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.package.here">
<application
android:name="com.package.here.MyApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
package com.package.here;
import android.content.Context;
public class MyClass {
//Usage of our contextor class
public void someMethod(){
Context context = Contextor.getInstance().getContext();
context.getResources().getDrawable(R.drawable.btn_add_extra);
}
}
package com.package.here;
import android.content.Context;
public class Contextor {
private static Contextor instance;
public static Contextor getInstance(){
if(instance==null){
instance = new Contextor();
}
return instance;
}
private Context mContext;
public Contextor(){}
public void init(Context context){
mContext = context;
}
public Context getContext(){
return mContext;
}
}
package com.package.here;
import android.app.Application;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Contextor.getInstance().init(getApplicationContext());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment