标签:知识点 被占用 attach seq 动作 imp csdn 包括 而且
Can‘t create handler inside thread that has not called Looper.prepare()
final Runnable runnable = new Runnable() {
@Override
public void run() {
//执行耗时操作
try {
Log.e("bm", "runnable线程: " + Thread.currentThread().getId()+ " name:" + Thread.currentThread().getName());
Thread.sleep(2000);
Log.e("bm", "执行完耗时操作了~");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
new Thread() {
public void run() {
Looper.prepare();
new Handler().post(runnable);//在子线程中直接去new 一个handler
Looper.loop(); //这种情况下,Runnable对象是运行在子线程中的,可以进行联网操作,但是不能更新UI
}
}.start();
final Runnable runnable = new Runnable() {
@Override
public void run() {
//执行耗时操作
try {
Log.e("bm", "runnable线程: " + Thread.currentThread().getId()+ " name:" + Thread.currentThread().getName());
Thread.sleep(2000);
Log.e("bm", "执行完耗时操作了~");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
new Thread() {
public void run() {
//在子线程中直接去new 一个handler
new Handler(Looper.getMainLooper()).post(runnable);
//这种情况下,Runnable对象是运行在主线程中的,不可以进行联网操作,但是可以更新UI
}
}.start();
百度google大家多说的是任务管理器 kill掉adb 或者重启adb server,但我任务管理器就没有adb ,猜测是某个程序占用了adb端口。于是按此思路查找。
5037为adb默认端口 查看该端口情况如下:
netstat -aon|findstr "5037"
TCP 127.0.0.1:5037 0.0.0.0:0 LISTENING 6540
发现6540占用了 5037端口,继续查看6540的task,发现是wandoujia .如下所示
tasklist|findstr "6540"
wandoujia_daemon.exe 6540 Console 1 4,276 K
接下来问题就好解决了,在任务管理器kill掉wandoujia_daemon.exe ,运行android程序,ok .
1.关闭xx荚进程
2.adb kill-server
3.adb start-server
java.lang.IllegalStateException: ExpectedBEGIN_OBJECT but was STRING at line 1 column 1 path $
/**
* 判断是否是json结构。这种判断不是很严谨
*/
public static boolean isJson(String value) {
try {
new JSONObject(value);
} catch (JSONException e) {
return false;
}
return true;
}
/**
* 判断是否是json结构
*/
public static boolean isGoodJson(String json) {
try {
new JsonParser().parse(json);
return true;
} catch (JsonParseException e) {
System.out.println("bad json: " + json);
return false;
}
}
android.content.ActivityNotFoundException: No Activity found to handle Intent
public class ActivityNotFoundException extends RuntimeException
{
public ActivityNotFoundException()
{
}
public ActivityNotFoundException(String name)
{
super(name);
}
};
Intent intent = new Intent(Intent.ACTION_SENDTO,url);
try {
context.startActivity(intent);
} catch(ActivityNotFoundException exception) {
Toast.makeText(this, "no activity", Toast.LENGTH_SHORT).show();
}
//避免安装了应用宝的用户点击其他外部链接走此方法导致崩溃
//判断是否用应用宝客户端
if(AppUtils.isPkgInstalled(AdDetailActivity.this,"com.tencent.android.qqdownloader")){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity( intent);
}
出错代码位置
public static String softVersionName(Context context) {
PackageInfo info = null;
try {
info = context.getPackageManager().getPackageInfo( context.getPackageName(), 0); //在这里
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return info.versionName;
}
public static String softVersionName(Context context) {
PackageInfo info = null;
try {//增加同步块
synchronized (context) {
info =context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
}
return info.versionName;
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
private void test() {
//这个Demo就是同时创建两个线程来进行Binder调用.
for (int i = 0; i < 2; i++) {
new Thread() {
@Override
public void run() {
int count = 0;
List<PackageInfo> list = getPackageManager().getInstalledPackages(0);
for (PackageInfo info : list) {
if(count >=1000){
break;
}
try {
PackageInfo pi = getPackageManager().getPackageInfo(info.packageName, PackageManager.GET_ACTIVITIES);
} catch (PackageManager.NameNotFoundException e) {
}
}
}
}.start();
}
}
}
synchronized(MainActivity.class){
PackageInfo pi = getPackageManager() .getPackageInfo(info.packageName, PackageManager.GET_ACTIVITIES);
}
View=com.android.internal.policy.impl.PhoneWindow$DecorView{22a4fb16 V.E..... R.....ID 0,0-1080,1020} not attached to window manager
com.flyco.dialog.widget.base.BaseDialog.superDismiss(BaseDialog.java)
Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { act=initApplication cmp=com.paidian.hwmc/.service.InitializeService }: app is in background uid UidRecord{a37d28d u0a386 TRNB bg:+5m30s482ms idle procs:3 seq(0,0,0)}
@Override
public void onBackPressed() {
if (!mFragments.getSupportFragmentManager().popBackStackImmediate()) {
super.onBackPressed();
}
}
public void onBackPressed() {
if (mActionBar != null && mActionBar.collapseActionView()) {
return;
}
if (!mFragments.getFragmentManager().popBackStackImmediate()) {
finishAfterTransition();
}
}
public void finishAfterTransition() {
if (!mActivityTransitionState.startExitBackTransition(this)) {
finish();
}
}
@Override
public boolean popBackStackImmediate() {
checkStateLoss();
executePendingTransactions();
return popBackStackState(mHost.getHandler(), null, -1, 0);
}
private void checkStateLoss() {
if (mStateSaved) {
throw new IllegalStateException(
"Can not perform this action after onSaveInstanceState");
}
if (mNoTransactionsBecause != null) {
throw new IllegalStateException(
"Can not perform this action inside of " + mNoTransactionsBecause);
}
}
if (!isFinishing()) {
super.onBackPressed();
}
在Fragment中直接调用
private MActivity mActivity;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mActivity = (MActivity) activity;
}
@Override
public void onDetach() {
super.onDetach();
mActivity = null;
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Parcelable p = mFragments.saveAllState();
if (p != null) {
outState.putParcelable(FRAGMENTS_TAG, p);
}
……
}
@SuppressWarnings("deprecation")
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
mFragments.attachHost(null /*parent*/);
super.onCreate(savedInstanceState);
NonConfigurationInstances nc = (NonConfigurationInstances) getLastNonConfigurationInstance();
if (nc != null) {
mFragments.restoreLoaderNonConfig(nc.loaders);
}
if (savedInstanceState != null) {
Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG);
mFragments.restoreAllState(p, nc != null ? nc.fragments : null);
……
}
if (mPendingFragmentActivityResults == null) {
mPendingFragmentActivityResults = new SparseArrayCompat<>();
mNextCandidateRequestIndex = 0;
}
mFragments.dispatchCreate();
}
if(savedInstanceState!= null){
String FRAGMENTS_TAG = "Android:support:fragments";
savedInstanceState.remove(FRAGMENTS_TAG);
}
标签:知识点 被占用 attach seq 动作 imp csdn 包括 而且
原文地址:https://www.cnblogs.com/yc211/p/9837154.html