Android 调用执行时不执行任何操作
这是我的asynctask类Android 调用执行时不执行任何操作,android,android-asynctask,Android,Android Asynctask,这是我的asynctask类 public class UpdatingNews extends AsyncTask<String, Void, String> { private Database_WebService webservice; private Context mContext; public UpdatingNews(Context context){ this.mContext = context; }
public class UpdatingNews extends AsyncTask<String, Void, String> {
private Database_WebService webservice;
private Context mContext;
public UpdatingNews(Context context){
this.mContext = context;
}
@Override
protected String doInBackground(String... params) {
webservice = new Database_WebService(mContext);
webservice.updateallCatNews();
webservice.UpdateAllNews();
return null;
}
@Override
protected void onPostExecute(String result) {
startActivity(new Intent(Main_Launcher.this,
Main_FormNewUser.class));
finish();
}
}
update = new UpdatingNews(this);
check = webservice.CheckSurveySubmit();
int secondsDelayed = 3;
new Handler().postDelayed(new Runnable() {
public void run() {
if (check == 0) {
update.execute("...");
}
if (check == 1) {
startActivity(new Intent(Main_Launcher.this,
Main_AllLatestNews.class));
finish();
}
}
}, secondsDelayed * 1000);
webservice.updateallCatNews();
webservice.UpdateAllNews();
它没有发挥作用
public class UpdatingNews extends AsyncTask<String, Void, String> {
private Database_WebService webservice;
private Context mContext;
public UpdatingNews(Context context){
this.mContext = context;
}
@Override
protected String doInBackground(String... params) {
webservice = new Database_WebService(mContext);
webservice.updateallCatNews();
webservice.UpdateAllNews();
return null;
}
@Override
protected void onPostExecute(String result) {
startActivity(new Intent(Main_Launcher.this,
Main_FormNewUser.class));
finish();
}
}
update = new UpdatingNews(this);
check = webservice.CheckSurveySubmit();
int secondsDelayed = 3;
new Handler().postDelayed(new Runnable() {
public void run() {
if (check == 0) {
update.execute("...");
}
if (check == 1) {
startActivity(new Intent(Main_Launcher.this,
Main_AllLatestNews.class));
finish();
}
}
}, secondsDelayed * 1000);
webservice.updateallCatNews();
webservice.UpdateAllNews();
有什么问题吗?更新新闻是一项异步任务。在跑步过程中,您启动了任务,但随后立即启动另一项活动,而没有完成任务。最有可能的情况是,android移动到主要的新用户活动,但任务仍在后台运行。
所以,很有可能你的第二次跑步实际上得到了第一次跑步的结果
如果您需要在抓取新闻后显示下一个活动,则应将asynctask中的startActivity语句移动到onPostExecute。查看代码后,我认为xandy是正确的。Main_FormNewUser活动与异步任务并行执行 我的意思是第一次运行alt+f11,不执行任何操作,然后退出并运行第二次运行alt+f12,执行。我以前试过,在OnPostExecute中启动活动根据您在此处发布的内容,很难进一步确定它不起作用的原因。不知道您是如何执行更新的,也不知道您是如何评估未执行的更新的。更新新闻真的被调用了吗?我已经更新了帖子,请再看看@Aniket RaneWhat is Database\u WebService?Database\u WebService包含那些处理sqlite数据库的函数,除非你在这里发布所有源CDOE,包括WebService、activity等,否则不可能知道它有什么问题。