-5

I want to print the list of currently running application, I am new in android please help. I want to know how to print this log in textview.

final ActivityManager activityManager = (ActivityManager) 
getSystemService(Context.ACTIVITY_SERVICE);
final List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

for (int i = 0; i < recentTasks.size(); i++) 
 {
   Log.d("Executed app", "Application executed : " 
   +recentTasks.get(i).baseActivity.toShortString()+ "\t\t ID: 
  "+recentTasks.get(i).id+"");         
}
Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62

3 Answers3

2

Try this :

Take a LinearLayout with orientation vertical in layout file. find reference of that layout and add textview to that layout.

        final ActivityManager activityManager = (ActivityManager) 
        getSystemService(Context.ACTIVITY_SERVICE);
        final List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);
        View linearLayout =  findViewById(R.id.info);

        for (int i = 0; i < recentTasks.size(); i++) 
         {
            TextView valueTV = new TextView(this);
            valueTV.setText(recentTasks.get(i).baseActivity.toShortString()+ "\t\t ID: 
      "+recentTasks.get(i).id);
            valueTV.setId(i);
            valueTV.setLayoutParams(new   LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));

            ((LinearLayout) linearLayout).addView(valueTV);

        }
Goku
  • 9,102
  • 8
  • 50
  • 81
1

Its not proper way to print log in TextView. Just see your logs in console/logcat.

Prashant Jajal
  • 3,469
  • 5
  • 24
  • 38
  • 2
    he want to print the list of currently running application in a TextView **Read Question again** – Goku Jan 01 '18 at 07:18
0

use this way

yourtextview.setText("Application executed : " 
   +recentTasks.get(i).baseActivity.toShortString()+ "\t\t ID: 
  "+recentTasks.get(i).id+"\n");
ND1010_
  • 3,743
  • 24
  • 41
Santanu Sur
  • 10,997
  • 7
  • 33
  • 52