I need to start my intent after finishing the download of the image from the url without any action from the user of the application itself.
This is my activity which first will download the image and after that it will start the 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);
}
The MyAsnyc does fine and downloads the image correctly, but the second part from the code which starts the intent while downloading the image so the image will be corrupted so it causes an exception.
How can I make the intent start ONCE the image will be ready and finished download?