I have a little application with 2 activities (say A and B) and an appWidget. When I click on the widget I start an activity, that animate the widget while do some stuff. I make it this way;
Intent intent = new Intent(context, DialogActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
RemoteViews.setOnClickPendingIntent(R.id.imageButton1, pendingIntent);
then the activity in the onCreate does this:
Paint p = new Paint();
p.setStyle(Paint.Style.FILL);
p.setColor(Color.TRANSPARENT);
logger.debug("inizializzo movie"); //$NON-NLS-1$
Movie movie;
InputStream is = null;
long moviestart = 0;
is = this.getResources().openRawResource(R.drawable.gifanimata);
movie = Movie.decodeStream(is);
taskIsrunning = true;
//this is an AsyncTask that at the end of the work sets taskIsrunning = false
new InitTask().execute(this);
while (taskIsrunning) {
Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawRect(0, 0, 100, 100, p);
long now = android.os.SystemClock.uptimeMillis();
if (moviestart == 0) { // first time
moviestart = now;
}
int relTime = (int) ((now - moviestart) % movie.duration());
movie.setTime(relTime);
movie.draw(canvas, 0, 0);
updateViews.setImageViewBitmap(R.id.imageButton1, bitmap);
widgetManager.updateAppWidget(theWidget, updateViews);
try {
Thread.sleep(500);
} catch (Exception e) {
throw e;
}
}
at the end of all, from this activity (witch is completely transparent) I show a dialog. This works just like I want, but here is the problem:
When I launch the activity, if previously I opened the first activity of the application (activity A) and closed it with the home button (the activity remain so in the stack) instead of closing it with back button, the moment of showing the dialog from the activity launched by the widget, the dialog is shown, but the activity A as well.
I tryied setting on manifest android:noHistory="true" and the problem is solved, but if from activity A i launch activity B, the back button will not show back activity A.