• We just launched and are currently in beta. Join us as we build and grow the community.

How to display Total Memory, Used Memory, and Available Memory in your Android Phone using Basic4Android

runox

Affiliate Deal Closer
R Rep
0
0
0
Rep
0
R Vouches
0
0
0
Vouches
0
Posts
121
Likes
74
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
This is my other tutorial on how to find and display your available memory, used memory, and total memory in your phone.

Since Android devices are usually battery-powered, Android is designed to manage memory (RAM) to keep power consumption at a minimum, in contrast to desktop operating systems which generally assume they are connected to unlimited mains electricity. When an Android app is no longer in use, the system will automatically suspend it in memory – while the app is still technically "open", suspended apps consume no resources and sit idly in the background until needed again. This has the dual benefit of increasing the general responsiveness of Android devices, since apps don't need to be closed and reopened from scratch each time, but also ensuring background apps don't consume power needlessly. Thus, it is really important to manage our memory in Android phones.

On this, you need to create Three Labels and named it as "lblAvail" for displaying the Available Memory, "lblTotal" for displaying the Total Memory, and "lblUsed" for displaying the Used Memory. You need also to create one button and named it btnMemory to display all of this memory in one. Next, named your abstract design as "main". Your abstract designer will be like this one below:

abstractdesign.png


Declare your variable in the Sub_Global like this:
  1. Sub

    Globals
  2. 'These global variables will be redeclared each time the activity is created.
  3. 'These variables can only be accessed from this module.
  4. Dim

    ph As

    ICOSPhone
  5. Dim

    btnMemory As

    Button
  6. Dim

    lblAvail As

    Label
  7. Dim

    lblTotal As

    Label
  8. Dim

    lblUsed As

    Label
  9. End

    Sub

Dim

ph As

ICOSPhone

- ph here is our variable for ICOSPhone in which it has all the necessary libraries in using phone utilities.
Dim

lblAvail As

Label

- we use this label to display the the Available Memory of your phone.
Dim

lblTotal As

Label

- we use this label to display the the Total Memory of your phone.
Dim

lblUsed As

Label

- we use this label to display the the Used Memory of your phone.

Now create a new activity. It should look like this:

  1. Sub

    Activity_Create(FirstTime As

    Boolean

    )
  2. 'Do not forget to load the layout file created with the visual designer. For example:
  3. Activity.LoadLayout("main"

    )
  4. End

    Sub

Now your activity when run will look like this below:

firstrun.png


Next, type the following code below. That this code means to display the all the values of our memory when our btnMemory is click.
  1. Sub

    btnMemory_Click
  2. lblUsed.Text = ph.UsedMemory
  3. lblAvail.Text = ph.AvailMemory
  4. lblTotal.Text = ph.TotalMemory
  5. End

    Sub

The ph.UsedMemory here is the method used to display the Used Memory, ph.AvailMemory for displaying Available Memory, and ph.TotalMemory for displaying Total Memory.

When you click this button, it will display like this image below:

finalimage_0.png


Here's the full code for this tutorial:

  1. Sub

    Process_Globals
  2. 'These global variables will be declared once when the application starts.
  3. 'These variables can be accessed from all modules.
  4. End

    Sub

  5. Sub

    Globals
  6. 'These global variables will be redeclared each time the activity is created.
  7. 'These variables can only be accessed from this module.
  8. Dim

    ph As

    ICOSPhone
  9. Dim

    btnMemory As

    Button
  10. Dim

    lblAvail As

    Label
  11. Dim

    lblTotal As

    Label
  12. Dim

    lblUsed As

    Label
  13. End

    Sub

  14. Sub

    Activity_Create(FirstTime As

    Boolean

    )
  15. 'Do not forget to load the layout file created with the visual designer. For example:
  16. Activity.LoadLayout("main"

    )
  17. End

    Sub
  18. Sub

    Activity_Resume
  19. End

    Sub

  20. Sub

    Activity_Pause (UserClosed As

    Boolean

    )

  21. End

    Sub


  22. Sub

    btnMemory_Click
  23. lblUsed.Text = ph.UsedMemory
  24. lblAvail.Text = ph.AvailMemory
  25. lblTotal.Text = ph.TotalMemory
  26. End

    Sub

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.

Best Regards,

Engr. Lyndon R. Bermoy

IT Instructor/System Developer/Android Developer
STI College - Surigao City
Mobile: 09488225971
E-mail:[email protected]

Follow and add me in my Facebook Account: https://www.facebook.com/donzzsky


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,341

323,350

Top