我需要在完成从 url 下载图像后开始我的意图,而不需要应用程序本身的用户采取任何行动。
这是我的活动,它首先会下载图像,然后会启动意图。
//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 做得很好并且可以正确下载图像,但是代码的第二部分在下载图像时启动了意图,因此图像将被损坏,从而导致异常。
一旦图像准备好并完成下载,如何使意图开始?