0

How can i put this in a textview?

ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
memoryInfo.availMem;

the textview id is for example freemem. The textview is in a second tab of a swipeview.thans

Atlas91
  • 5,754
  • 17
  • 69
  • 141

1 Answers1

2

Put this in your layout XML

  <TextView android:id="@+id/myTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

and this in your activity:

   TextView myTextView = (TextView)findViewById(R.id.myTextView);
    ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
    activityManager.getMemoryInfo(memoryInfo);
    myTextView.setText("" + memoryInfo.availMem);

memoryInfo.availMem is the available memory on the system. memoryInfo.totalMem is the total memory accessible by the kernel.

Here is a link to a good answer about memory availability.

Community
  • 1
  • 1
HalR
  • 11,411
  • 5
  • 48
  • 80