Last active
December 30, 2015 07:46
-
-
Save parahall/eadd11ec6b1a64ad3f70 to your computer and use it in GitHub Desktop.
Android Academy Weekly Quizz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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