This is Program is used for seperate thread , which is execute ProgressDialog Box........
program1 : MainActivity.java
package com.example.progressdialogdemo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.ProgressDialog;
import android.util.Log;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends Activity {
private ProgressDialog dialog ;
private Handler myhandler ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showProgressbar();
new Thread(new Runnable() {
@Override
public void run() {
SecondClass obj = new SecondClass(myhandler,dialog);
obj.doWork();
}
}).start();
}
private void showProgressbar() {
dialog = new ProgressDialog(MainActivity.this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER) ;
dialog.setTitle("Data Sending To Server");
dialog.setMessage("Loading..Wait..Till It Send..");
//dialog.show();
dialog.setCancelable(false);
dialog.show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
program 2 : SecondClass.java
package com.example.progressdialogdemo;
import android.app.ProgressDialog;
import android.os.Handler;
public class SecondClass {
private ProgressDialog dialog ;
private Handler hand ;
public SecondClass(Handler myhandler, ProgressDialog dialog2) {
hand = myhandler ;
dialog = dialog2 ;
}
public void doWork() {
dialog.show();
}
}
xml part :
<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"
tools:context=".MainActivity" >
</RelativeLayout>
program1 : MainActivity.java
package com.example.progressdialogdemo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.ProgressDialog;
import android.util.Log;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends Activity {
private ProgressDialog dialog ;
private Handler myhandler ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showProgressbar();
new Thread(new Runnable() {
@Override
public void run() {
SecondClass obj = new SecondClass(myhandler,dialog);
obj.doWork();
}
}).start();
}
private void showProgressbar() {
dialog = new ProgressDialog(MainActivity.this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER) ;
dialog.setTitle("Data Sending To Server");
dialog.setMessage("Loading..Wait..Till It Send..");
//dialog.show();
dialog.setCancelable(false);
dialog.show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
program 2 : SecondClass.java
package com.example.progressdialogdemo;
import android.app.ProgressDialog;
import android.os.Handler;
public class SecondClass {
private ProgressDialog dialog ;
private Handler hand ;
public SecondClass(Handler myhandler, ProgressDialog dialog2) {
hand = myhandler ;
dialog = dialog2 ;
}
public void doWork() {
dialog.show();
}
}
xml part :
<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"
tools:context=".MainActivity" >
</RelativeLayout>