You have to set it to a value and that looks totally wrong. try:
ActivityManager minfo = new ActivityManager.MemoryInfo();
String TAG = "memory";
minfo.getMemoryInfo();
idk what the arguments are for the memory info things tho.
I need to get available memory.My code is like this
MemoryInfo minfo=new ActivityManager.MemoryInfo();
String TAG="Memory";
ActivityManager mgr;
mgr.getMemoryInfo(minfo);
But when i am compiling this show me the error :
Local Variable mgr have not been initialised.How to initialise the activityManager.Please show me the way to do it.
Thanks in advance
saru
You have to set it to a value and that looks totally wrong. try:
ActivityManager minfo = new ActivityManager.MemoryInfo();
String TAG = "memory";
minfo.getMemoryInfo();
idk what the arguments are for the memory info things tho.
Sprint HTC Evo 4G - Rooted
CyanogenMod 6.0.0 Froyo 2.2 ROM
CM6-Snap 7.6
Check out my site Exodus Apps, we will be developing applications for the Notion Ink Adam Tablet soon!
Follow us on Twitter @Exodusapps
Follow me on Twitter @Aaron_Blank
I am no Android developer nor Java expert, but you need to retrieve an ActivityManager object from something. As it stands now the variable mgr points to nothing and is, therefore, uninitialized.
I tried ur way.But it again show me the error that can't convert from ActivityManager.MemoryInfo into ActivityManager.So what i need to do?
Help me.
Thanks in advance
saru
This is an old thread but if anyone still needs this information here is one way to do it.
#1. Context.getSystemService.( ACTIVITY_SERVICE ) call from your Activity will return an ActivityManager
#2. Create your ActivityManager.MemoryInfo to hold the memory information like this in your code:
ActivityManager.MemoryInfo mInfo = new ActivityManager.MemoryInfo ();
#2. Pass the ActivityManager.MemoryInfo object to the ActivityManager using getMemoryInfo() method and you can then retrive the ActivityManager.MemoryInfo's availMem, lowMemory and threshold values.
So your complete code would look something like this:
***
ActivityManager actvityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
ActivityManager.MemoryInfo mInfo = new ActivityManager.MemoryInfo ();
actvityManager.getMemoryInfo( mInfo );
// Print to log and read in DDMS
Log.i( TAG, " minfo.availMem " + mInfo.availMem );
Log.i( TAG, " minfo.lowMemory " + mInfo.lowMemory );
Log.i( TAG, " minfo.threshold " + mInfo.threshold );
***
Belated information but I hope it helps.
hi,
I am trying your code but it is not working. Do we need to find to define getMemoryInfo()?
Regards,
Bookmarks