首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在安卓系统中正确地从PostExecute启动活动?

如何在安卓系统中正确地从PostExecute启动活动?
EN

Stack Overflow用户
提问于 2012-02-03 02:41:02
回答 3查看 37K关注 0票数 22

我有一个AsyncTask,它用来自互联网的解析数据填充一个自定义列表。

在PostExecute中,我填充该列表,并准备将其转移到新活动中。

我这样做:

@Override
protected void onPostExecute(List<VideoDataDescription> result) 
{
    super.onPostExecute(result);
    MainActivity.progressDialog.dismiss();

    context.startActivity(new Intent(context, ResultsQueryActivity.class));


}

where上下文

    private Context context;

在LogCat中,执行完这段代码后,我得到了一个Java.lang.NullPointerException。在我这样做的时候启动一个活动是可能的并且是正确的吗?

我已经添加了更新

    private Context mContext;


public YoutubeAndYahooParser(Context context) 
{
    super();
    this.mContext = context;
}

初始化上下文并调用

YoutubeAndYahooParser youtubeAndYahooParser = new YoutubeAndYahooParser(ResultsQueryActivity.this);
                    youtubeAndYahooParser.execute("my string to pass in asynctak");

在此之后在PostExecute中

Intent intent = new Intent(mContext, ResultsQueryActivity.class);
 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 mContext.startActivity(intent);    

我添加了新的标志,因为我在接下来的LogCat中得到了:

*从活动上下文外部调用startActivity()需要FLAG_ACTIVITY_NEW_TASK标志。这真的是你想要的吗*

我说的对吗?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9118015

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档