Tuesday 19 March 2013

Progress Dialog showing when Back Ground Task Running in Android

package com.raja.vedioapp;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState)

{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new BackGround().execute("hi");
}
class BackGround extends AsyncTask<String, Void, String>
{
ProgressDialog progress;
@Override
protected String doInBackground(String... params)
{
for(int i=0;i<=10000;i++)
{
System.out.println("Background Task "+i);
}
return "success";
}

@Override
protected void onPostExecute(String result)
{
System.out.println("BackGround Task Completed Result is "+result);
progress.cancel();
}

@Override
protected void onPreExecute()
{
progress=ProgressDialog.show(MainActivity.this, "Progress", "Please Wait...",true);
}


}
}

1 comment:

  1. Hey There. I discovered your blog site making use of msn. This is an exceptionally well composed guide. I will make sure to bookmark it and come back to review more of your helpful information. Thanks for the post. I'll definitely return.

    ReplyDelete