I have an application widget that contains a button. Once I click the button, it takes the activity a while to load. In the activity that’s loaded, I have two asynch tasks that take a few seconds to execute. So, what I’d like to do is launch a progress dialog page while the activity is loading.
Since the widget icon is set up as an intent in onUpdate:
public class MyWidget extends AppWidgetProvider {
@Override
public void onEnabled(Context context) {
super.onEnabled(context);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
Intent messageIntent = new Intent(context, MyActivity.class);
messageIntent.setAction(ACTION_WIDGET_GROUP);
}
}
There is no specific “onClick” to initialize the progress dialog. In addition, I’m not inside of the activity yet, I’m launching the activity from the widget.
How and where do I set up a progress dialog in the widget for this to work? Does the progress dialog belong in the application widget?
The progress dialog doesn’t launch within the activity itself. Well it does, but it only starts after the activity loads:
public class HomeActivity extends Activity {
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.dashboard);
setupLayout();
callAsynchronousUsers(); // asynchronous call
getData(); // asynchronous call
}
. . .
}
Any and all help is appreciated.
Well, you can’t do that, the only way would be to launch a transparent activity in the middle that shows only a custom dialog with a progress bar and then launches the real activity. But is not an elegant solution, actually it sucks.
What I suggest is to open your activity right away and showing the progress bar there based on your AsyncTask, I think it is the standard way to do it. That’s what AsyncTask is for, you can execute hard work indipendently from the UI, in your case you would show a progress bar with a message.