有些是转的。

1.new Handler()不能在run()中执行
Can't create handler inside thread that has not called Looper.prepare() 原因:

在asyncTask的doInBackground()中,或Runable的run()中,或TimerTask的run()中

new Handler()就会失败。


2.TimerTask取消后就不能再用了

java.lang.IllegalStateException: TimerTask is scheduled already

当cancle掉一个TimerTask,这个Task就不能再用了。必须重新new一个。

nextStepTask = new NextStepTimerTask();
nextStepTimer.schedule(nextStepTask, 0, 1000);

3.加载字符串到String

WebpageActivity.this.getResources().getText(R.string.search_page_test).toString()

4.startActivity

很多人使用startActivity时候,会碰到如下的异常:

Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?


我曾经也遇到过,不过后来研究了一下之后,明白了原理,记下来,以为碰到同样困扰的兄弟们解惑。


都知道,Context中有一个startActivity方法,Activity继承自Context,重载了startActivity方法。如果使用Activity的startActivity方法,不会有任何限制,而如果使用Context的startActivity方法的话,就需要开启一个新的task,遇到上面那个异常的,都是因为使用了Context的startActivity方法。解决办法是,加一个flag。

  1. intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

5.android sdcard read-only file system 的解决办法

【解决方法】

在cmd窗口一条命令就可以了:
adb shell
mount -o remount rw /

//然后mkdir aaa试一下ok


LayoutInflater的构造

    /**     * Obtains the LayoutInflater from the given context.     */    public static LayoutInflater from(Context context) {        LayoutInflater LayoutInflater =                (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);        if (LayoutInflater == null) {            throw new AssertionError("LayoutInflater not found.");        }        return LayoutInflater;    }


s

TextView

style = "@android:style/TextAppearance.StatusBar.EventContent"//from api 9
android:textAppearance="?android:attr/textAppearanceSmall"

判断版本
if(android.os.Build.VERSION.SDK_INT<=android.os.Build.VERSION_CODES.FROYO)//这是小于等于2.2(api<=8)



Android permission 访问权限大全


s



s

更多相关文章

  1. 分支和循环(二)(零基础学习C语言)
  2. Android(安卓)硬件加速
  3. Android(安卓)检测SD卡是否可用
  4. android拖拽功能的实现原理
  5. Android之Canvas
  6. Android之关于onSaveInstanceState和onRestoreInstanceState触发
  7. 移动数据流程
  8. android 生成快捷方式(包括源码)
  9. 我的Android进阶之旅------>启动Activity的标准Action和标准Cate

随机推荐

  1. Linux系统的文件传输工具RZSZ
  2. 使用wdcp完成网站搭建
  3. linux忘记root密码的两种修改方法
  4. Linux Socket编程(不限Linux)
  5. Git - 将Github仓库与本地仓库同步?
  6. 新人求助:tensorflow官方文档里构建第一个
  7. Linux 驱动开发之内核模块开发 (三)—— 模
  8. 文本处理小工具SED用法
  9. Linux学习之文件系统权限及表示
  10. Linux daemon进程的应用、实现和原理