android studio遇到的错误

1、Error:Failed to resolve: com.android.support:appcompat-v7:27.0.0,sdkversion为27时报此错误

解决:build.gradle中android标签中加上

repositories {
        mavenLocal()
        mavenCentral()
        maven {                                  // <-- Add this
            url 'https://maven.google.com/'
            name 'Google'
        }
    }

2、加载一些so文件时报libxxx.so- text relocations错误

原因:从6.0起,即SDK Version>=23时,系统将会拒绝加载包含text relocations的共享库,同时输出错误Log

解决:点击打开链接

3、在非activity中用context.startActivity时,报错:Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

原因:使用Context的startActivity方法的話,就需要开启一个新的的task(我的待跳转的activity设置了singleTask)

解决:跳转时加 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );

4、定时问题

a.(Thread)开启子线程后,利用while(true)实现定时循环操作,再次调用此处时记得先停止线程:thread置为null,true置为false,如果里面有sleep,则要确认当前thread完全停止

代码示例:

Thread scheduleThread = null;
    boolean scheduleThreadWorking = true;
    //定时子线程
    private void scheduleThreadStart(final String s_res)
    {
        if( scheduleThread != null )
        {
            scheduleThreadWorking = false;
            scheduleThread = null;
        }

        scheduleThread = //定时更新课程表
                new Thread(){
                    @Override
                    public void run() {
                        while(scheduleThreadWorking){
                            try {
                                //do something...
                                Thread.sleep(TIME);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                };
        try {
            //设置此延时,目的在于防止停止线程时停不掉
            if( !scheduleThreadWorking )
                Thread.sleep(TIME);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        scheduleThreadWorking = true;
        scheduleThread.start();
    }
b.(Handler) 代码中用到了 mHandler.sendEmptyMessageDelayed(CODE_NOTICE, 8000);来做定时器,记得要在此前加上mHandler.removeMessages(CODE_NOTICE);,以免再次调用代码时出现重复问题

猜你喜欢

转载自blog.csdn.net/qq_26075861/article/details/79266917