从窗口小部件启动的活动会导致显示堆栈中的活动

时间:2012-01-14 22:58:17

标签: android android-appwidget activity-stack

我有一个带有2个活动的小应用程序(比如A和B)和appWidget。当我点击小部件时,我开始一个活动,在做一些事情的同时为小部件设置动画。我是这样做的;

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);

然后onCreate中的活动执行此操作:

    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;
    }
    }

最后,从这个活动(女巫完全透明)我展示了一个对话框。 这就像我想要的那样,但问题出在这里:

当我启动活动时,如果之前我打开了应用程序的第一个活动(活动A)并使用主页按钮关闭它(活动保持在堆栈中),而不是用后退按钮关闭它,从窗口小部件启动的活动显示对话框,显示对话框,但活动A也是如此。

我尝试设置清单android:noHistory =“true”并且问题已解决,但如果从活动A i启动活动B,后退按钮将不会显示活动A.

0 个答案:

没有答案