Android Community
Results 1 to 6 of 6

Thread: How to intialise ActivityManager

  1. #1
    Join Date
    Oct 2008
    Posts
    8

    Unhappy How to intialise ActivityManager


    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

  2. #2
    Join Date
    Sep 2008
    Posts
    683

    Default Re: How to intialise ActivityManager

    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

  3. #3
    Join Date
    Oct 2008
    Posts
    22

    Default Re: How to intialise ActivityManager

    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.

  4. #4
    Join Date
    Oct 2008
    Posts
    8

    Default Re: How to intialise ActivityManager

    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

  5. #5

    Default Re: How to intialise ActivityManager

    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.

  6. #6

    Default Re: How to intialise ActivityManager


    hi,
    I am trying your code but it is not working. Do we need to find to define getMemoryInfo()?

    Regards,

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •