I want to make switch from one activity to another when the progress bar reached to maximum.
Activity A
public class A extends Activity {
private ProgressBar progressBar;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.mainpage);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawable.main);
progressBar = (ProgressBar) findViewById(R.id.prog_bar);
new AsyncTask<Void, Integer, Integer>(){
@Override
protected Integer doInBackground(Void... params) {
int progressStatus = 0;
while (progressStatus < 5000) {
progressStatus++;
publishProgress(progressStatus);
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return 1;
}
@Override
protected void onProgressUpdate(Integer... values) {
progressBar.setProgress(values[0]);
}
protected void onPostExecute(Integer result) {
final Intent mainIntent = new Intent(A.this,B.class);
startActivity(mainIntent);
finish();
return;
}
}.execute();
}
}
But in this code the onPostExecute() method is not execting...I got stuck with the parameters of aSyncTask also... When I run this code in debug mode it returns from try block
try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); }
XML for this class
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="5dp"
android:background="@drawable/eggstation"
tools:context=".A" >
<TextView
android:id="@+id/dutech"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-5dp"
android:text="@string/text_data"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#00cccc"
android:textSize="25sp" />
<TextView
android:id="@+id/devby"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/dutech"
android:layout_marginBottom="5dp"
android:gravity="center"
android:text="Developed by:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#3399cc"
android:textSize="28sp" />
<ProgressBar
android:id="@+id/prog_bar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="1dp"
android:max="100"
android:layout_alignParentTop="true" />