来自Async子类的Android应用程序finish()

来自Async子类的Android应用程序finish(),android,android-intent,android-activity,Android,Android Intent,Android Activity,我使用异步类作为子类。成功完成后,我想去一个活动,假设ListActivity 但是在到达ListActivity之后,当我单击“返回”时,它会返回到上一个活动本身。所以我尝试了“finish()”。但是我犯了一个错误 我的代码看起来像 protected void onPostExecute(String result) { if(flags.equals(1)){ Intent homepage = new Intent(GCMIntentServi

我使用异步类作为子类。成功完成后,我想去一个活动,假设ListActivity

但是在到达ListActivity之后,当我单击“返回”时,它会返回到上一个活动本身。所以我尝试了“finish()”。但是我犯了一个错误

我的代码看起来像

protected void onPostExecute(String result) {

        if(flags.equals(1)){
            Intent homepage = new Intent(GCMIntentService.this, ListActivity.class);
            homepage.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(homepage);
            finish();
        }
        else {
有人知道如何在异步子类中使用finish()吗


提前感谢

在启动意图后删除当前活动,调用
currentActivity.this.finish()


YourClassName.this.finish()
其中
YourClassName
是包含
异步任务的类的名称

编辑:
gcminentservice
实际上是
GCMBaseIntentService
的一个实例,而不是
活动
。因此它没有
finish()
方法。停止服务的正确方法是调用
stopSelf()
(doc)。因此,要停止服务,您应该调用
gcminentservice.this.stopSelf()
。您可能不需要这样做,因为当您开始新的
活动时,Android很可能会帮您处理


注意:
GCMBaseIntentService
已被弃用,现在最好使用。

请发布您的错误和堆栈跟踪
homepage.setFlags(Intent.FLAG\u ACTIVITY\u NEW\u TASK | Intent.FLAG\u ACTIVITY\u CLEAR\u TOP)
gcminentservice.this.finish()@Geralt_Encore这是他正在进行的活动starting@Vee实际上,activity就是ListActivity。当我尝试此方法时,我遇到了以下错误。类型gcminentServiceIs
gcminentService
activity
Service
的finish()未定义?它是什么?gcminentservice的子类不是活动。类似于GCM的公共类GCMinentService扩展了GCMBaseintService。有什么想法吗?嗨,当我尝试此方法时,我遇到以下错误。当我尝试gcminentservice.this.finish()时,类型gcminentservice的finish()未定义;有什么想法吗(
    protected void onPostExecute(String result) {

        if(flags.equals(1)){
            Intent homepage = new Intent(GCMIntentService.this, ListActivity.class);
            homepage.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(homepage);
            currentActivity.this.finish()
            ...
         }