相关疑难解决方法(0)

Android:Activity.runOnUiThread和View.post有什么区别?

有什么区别Activity.runOnUiThreadView.post,有人可以解释一下吗?

android

92
推荐指数
3
解决办法
3万
查看次数

Activity.runOnUiThread(runnable action)和Handler.post()之间有什么区别?

使用Activity.runOnUiThreadHandler.post(runnable action)在Android中有什么区别/优点/缺点?

android

30
推荐指数
1
解决办法
1万
查看次数

Runnable已成功发布但未运行

在现有的Android项目中,我遇到了以下代码(我插入了调试垃圾)

ImageView img = null;

public void onCreate(...) {

    img = (ImageView)findViewById(R.id.image);

    new Thread() {
        public void run() {
            final Bitmap bmp = BitmapFactory.decodeFile("/sdcard/someImage.jpg");
            System.out.println("bitmap: "+bmp.toString()+" img: "+img.toString());
            if ( !img.post(new Runnable() {
                public void run() {
                    System.out.println("setting bitmap...");
                    img.setImageBitmap(bmp);
                    System.out.println("bitmap set.");
                }
            }) ) System.out.println("Runnable won't run!");
            System.out.println("runnable posted");
        }
    }.start();
Run Code Online (Sandbox Code Playgroud)

Android开发的新手,并且已经开始搜索,我知道这是在不阻塞主(UI)线程的情况下执行操作的方法,同时仍然在解码后在UI线程上设置图像.(至少根据android-developers)(我已通过Thread.currentThread().getName()在各个地方登录验证)

现在有时图像不会出现,stdout只说

I/System.out( 8066): bitmap: android.graphics.Bitmap@432f3ee8 img: android.widget.ImageView@4339d698
I/System.out( 8066): runnable posted
Run Code Online (Sandbox Code Playgroud)

没有来自Runnable的消息的痕迹.所以看起来Runnable没有run(),尽管img.post()返回true.拉入ImageView onCreate()并声明它final …

java multithreading android runnable

24
推荐指数
4
解决办法
2万
查看次数

标签 统计

android ×3

java ×1

multithreading ×1

runnable ×1