分享自己编的小程序,activity,查询运行中的进程
aide吧
全部回复
仅看楼主
level 9
逍遥hell 楼主
package com.mycompany.myapp;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.app.*;
import java.util.*;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button as=(Button)findViewById(R.id.mainbutton1);
as.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View p)
{
ListView sa=(ListView)findViewById(R.id.mainListView1);
try{
ActivityManager qw=(ActivityManager)MainActivity.this.getSystemService(ACTIVITY_SERVICE);
ArrayList<String> ary=new ArrayList<String>();
List<ActivityManager.RunningAppProcessInfo> act=qw.getRunningAppProcesses();
int i=1;
for(ActivityManager.RunningAppProcessInfo a:act)
{
ary.add((i++)+":"+a.processName+" id "+a.pid+" uid "+a.uid);
}
ArrayAdapter shi=new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,ary);
sa.setAdapter(shi);
}
catch(Exception e)
{
Toast.makeText(MainActivity.this,e.toString(),Toast.LENGTH_LONG).show();
}
}
});
}
}
2016年05月18日 04点05分 1
level 9
逍遥hell 楼主
没做优化,只是完成核心
2016年05月18日 04点05分 2
level 7
牛逼啊~
2016年05月18日 14点05分 3
初学[太开心]
2016年05月18日 22点05分
level 12
帮顶
2016年05月18日 15点05分 4
谢谢
2016年05月18日 22点05分
level 15
这个不错,收藏
 ✎﹏﹏
我掐指一算,楼主的贴子发表于11小时47分钟前,应该是2016-05-18 12:16发的。
2016年05月18日 16点05分 5
分析帝现世,大家围观[真棒]
2016年05月18日 22点05分
level 9
赞一个
2016年05月18日 23点05分 6
谢谢
2016年05月19日 00点05分
level 9
逍遥hell 楼主
改进了一下,可查询服务和进程,服务最多99个,还有点小bug
2016年05月19日 00点05分 7
level 9
逍遥hell 楼主
package com.mycompany.myapp;
import android.app.*;
import android.content.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.view.inputmethod.*;
import android.widget.*;
import java.util.*;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button as=(Button)findViewById(R.id.mainbutton1);
Button jk=(Button)findViewById(R.id.mainButton2);
final ListView sa=(ListView)findViewById(R.id.mainListView1);
final EditText num=(EditText)findViewById(R.id.mainEditText1);
num.setOnClickListener(new OnClickListener()
{
public void onClick(View p)
{
InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
});
jk.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View p)
{
int geshu=1;
try{
geshu=Integer.parseInt(num.getText().toString());
//Toast.makeText(MainActivity.this,num.getText().toString(),Toast.LENGTH_LONG).show();
if(geshu>=101|geshu<1)
{geshu=30;
Toast.makeText(MainActivity.this,"看仔细再输入哦!不能超过100个,太多,我怕你手机受不了。给你看三十个!",Toast.LENGTH_LONG).show();
}
else
{}}
catch(Exception e)
{
Toast.makeText(MainActivity.this,e.toString(),Toast.LENGTH_LONG).show();
}
new GetServices(geshu,sa,MainActivity.this);
}
});
as.setOnClickListener(new OnClickListener()
{
public void onClick(View p)
{
new GetProcess(sa,MainActivity.this);
}
});
}
}
class GetServices extends Activity
{
public GetServices(int num,ListView edit,MainActivity main)
{
try{
ActivityManager qw=(ActivityManager)main.getSystemService(ACTIVITY_SERVICE);
ArrayList<String> ary=new ArrayList<String>();
List<ActivityManager.RunningSer
2016年05月19日 00点05分 8
level 9
逍遥hell 楼主
2016年05月19日 01点05分 9
1.0版
2016年05月19日 01点05分
level 9
逍遥hell 楼主
默认30个服务
2016年05月19日 01点05分 10
lz大大,你的安卓是什么版本的?5.1.1表示只有自己的进程,是不是谷歌为了安全和谐了?
2018年05月15日 00点05分
@asfetdd 这个是支持4.4.4及以下版本,5.0开始api废弃了,要用另一种方法,详情百度
2018年05月17日 00点05分
2018年06月01日 13点06分
level 8
循环/proc
2018年05月17日 04点05分 11
1