【发布时间】:2012-07-25 13:37:34
【问题描述】:
我需要在完成从 url 下载图像后开始我的意图,而不需要应用程序本身的用户进行任何操作。
这是我的 Activity,它首先会下载图像,然后会启动 Intent。
//download image then start decod intent
public void download(View v)
{
//first download image
new MyAsnyc().execute();
//then start this intent
final Handler handler=new Handler();
final Runnable r = new Runnable()
{
public void run()
{
{
Intent intent1 = new Intent(Test_PROJECTActivity.this, DecodeActivity.class);
File path = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File file = new File(path, "DemoPictureX.png");
Log.d("file", file.getAbsolutePath());
intent1.putExtra("file", file.getAbsolutePath());
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
startActivity(intent1);
}
}
};
handler.postDelayed(r, 5000);
}
MyAsnyc 可以正常下载并正确下载图像,但代码的第二部分在下载图像时启动意图,因此图像将被损坏,从而导致异常。
如何在图像准备好并完成下载后启动意图?
【问题讨论】:
-
你在哪里下载图片?我没看到电话。
-
在 MyAsnyc 类中调用 new MyAsnyc().execute();
-
你能显示你的清单文件吗?
标签: android android-intent android-image android-internet android-handler