|
3 | 3 | import android.app.Activity;
|
4 | 4 | import android.os.Bundle;
|
5 | 5 | import android.view.View;
|
| 6 | +import android.widget.TextView; |
6 | 7 |
|
7 | 8 | import com.blankj.androidutilcode.R;
|
8 | 9 | import com.blankj.utilcode.utils.ProcessUtils;
|
9 | 10 | import com.blankj.utilcode.utils.ToastUtils;
|
10 | 11 |
|
| 12 | +import java.util.Iterator; |
| 13 | +import java.util.Set; |
| 14 | + |
11 | 15 | /**
|
12 | 16 | * <pre>
|
13 | 17 | * author: Blankj
|
|
19 | 23 | public class ProcessActivity extends Activity
|
20 | 24 | implements View.OnClickListener {
|
21 | 25 |
|
| 26 | + private TextView tvAboutProcess; |
| 27 | + |
22 | 28 | @Override
|
23 | 29 | protected void onCreate(Bundle savedInstanceState) {
|
24 | 30 | super.onCreate(savedInstanceState);
|
25 | 31 | setContentView(R.layout.activity_process);
|
26 | 32 |
|
27 | 33 | findViewById(R.id.btn_kill_all_background_processes).setOnClickListener(this);
|
| 34 | + tvAboutProcess = (TextView) findViewById(R.id.tv_about_process); |
| 35 | + |
| 36 | + Set<String> set = ProcessUtils.getAllBackgroundProcesses(this); |
| 37 | + tvAboutProcess.setText("getForegroundProcessName: " + ProcessUtils.getForegroundProcessName(this) |
| 38 | + + "\n\ngetAllBackgroundProcesses: " + getSetItems(set) |
| 39 | + + "\nsize: " + set.size()); |
28 | 40 | }
|
29 | 41 |
|
30 | 42 | @Override
|
31 | 43 | public void onClick(View view) {
|
32 | 44 | switch (view.getId()) {
|
33 | 45 | case R.id.btn_kill_all_background_processes:
|
34 |
| - ToastUtils.showShortToast(this, ProcessUtils.killAllBackgroundProcesses(this)); |
| 46 | + Set<String> set = ProcessUtils.getAllBackgroundProcesses(this); |
| 47 | + Set<String> set1 = ProcessUtils.killAllBackgroundProcesses(this); |
| 48 | + tvAboutProcess.setText("getForegroundProcessName: " + ProcessUtils.getForegroundProcessName(this) |
| 49 | + + "\n\ngetAllBackgroundProcesses: " + getSetItems(set) |
| 50 | + + "\nsize: " + set.size() |
| 51 | + + "\n\nkillAllBackgroundProcesses: " + getSetItems(set1) |
| 52 | + + "\nsize: " + set1.size()); |
35 | 53 | break;
|
36 | 54 | }
|
37 | 55 | }
|
| 56 | + |
| 57 | + private String getSetItems(Set<String> set) { |
| 58 | + Iterator<String> iterator = set.iterator(); |
| 59 | + StringBuilder sb = new StringBuilder(); |
| 60 | + while (iterator.hasNext()) { |
| 61 | + sb.append(iterator.next()).append("\n"); |
| 62 | + } |
| 63 | + return sb.toString(); |
| 64 | + } |
38 | 65 | }
|
0 commit comments