Skip to content

Instantly share code, notes, and snippets.

@vivdub
Created June 15, 2011 05:12
Show Gist options
  • Save vivdub/e444b1b7b2d4d2175204 to your computer and use it in GitHub Desktop.
Save vivdub/e444b1b7b2d4d2175204 to your computer and use it in GitHub Desktop.
The file that shows dialog, when started from service
package com.test;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
public class UpdateDBProgressDialog extends Activity {
private TextView tv;
private ProgressDialog pd;
private Handler handler;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
pd = ProgressDialog.show(this, "Updating Database", "The application is updating the database. Please wait.", true, false);
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
pd.dismiss();
}
};
Thread thread = new Thread(){
public void run() {
try{
Thread.sleep(2000);
handler.sendEmptyMessage(0);
}catch(Exception e){e.printStackTrace();}
}
};
thread.start();
new Thread(){public void run(){
try{
Thread.sleep(10000);
if(!MyService.RUNNING){
Intent i = new Intent(UpdateDBProgressDialog.this, MyService.class);
UpdateDBProgressDialog.this.startService(i);
}
}catch(Exception e){e.printStackTrace();}
}}.start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment