Skip to content

Commit 6d8ef79

Browse files
committed
Add example of providing an Application Context
1 parent 103291a commit 6d8ef79

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/AndroidClient/techstacks/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package="servicestack.net.techstacks" >
44

55
<application
6+
android:name=".TechStacksApplication"
67
android:allowBackup="true"
78
android:icon="@mipmap/logo_transparent"
89
android:label="@string/app_name"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package servicestack.net.techstacks;
2+
3+
import android.app.ActivityManager;
4+
import android.app.Application;
5+
import android.content.Context;
6+
7+
/**
8+
* Created by mythz on 12/8/2015.
9+
*/
10+
public class TechStacksApplication extends Application {
11+
private static Context ctx;
12+
13+
@Override
14+
public void onCreate() {
15+
super.onCreate();
16+
ctx = getApplicationContext();
17+
}
18+
19+
public static Context getContext() {
20+
return ctx;
21+
}
22+
23+
static ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
24+
public static ActivityManager.MemoryInfo getMemoryInfo(){
25+
ActivityManager mgr = (ActivityManager) TechStacksApplication.getContext()
26+
.getSystemService(Context.ACTIVITY_SERVICE);
27+
mgr.getMemoryInfo(memoryInfo);
28+
return memoryInfo;
29+
}
30+
}

0 commit comments

Comments
 (0)