我不知道我做错了,但onPostExecute不会被调用。
I am not sure what I am doing wrong but onPostExecute never gets called.
在创建了一个名为BaseActivity.java一个基类 从我原来的活动我扩展这个类。 在里面BaseActivity放置PostToOpenFeint类从UI线程的主要活动称之为我做的: Created a base class called BaseActivity.java From my original Activity I extended this class. Placed PostToOpenFeint class inside BaseActivity
Called it from the UI thread from the main activity my doing:
new PostToOpenFeint.execute();
上的preExecute(),doInBackground(..)被触发,但由于某些原因,onPostExecute不会被调用。
The onPreExecute(), doInBackground(..) gets triggered, but for some reason the onPostExecute never gets called.
感谢你在前进!
戴夫
private class PostToOpenFeint extends AsyncTask<Void, Void, Void> {
/*
* (non-Javadoc)
*
* @see android.os.AsyncTask#doInBackground(Params[])
*/
@Override
protected Void doInBackground(Void... params) {
// does all the work here
return null;
}
/*
* (non-Javadoc)
*
* @see android.os.AsyncTask#onPostExecute(java.lang.Object)
*/
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
Toast.makeText(MainScreen.this, "Done syncing", Toast.LENGTH_LONG).show();
}
/*
* (non-Javadoc)
*
* @see android.os.AsyncTask#onPreExecute()
*/
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
Toast.makeText(MainScreen.this, "About to sync all your scores", Toast.LENGTH_LONG).show();
}
寻找到它多了,这是我能够观察到。例如,如果我把这个电话:
Looking into it more, this is what I was able to observe. For example if I place this call:
new PostToOpenFeint.execute();
右边的活性的onCreate后,然后一切工作正常。如果我把这个电话说,一个按钮监听器里。
right after onCreate of the Activity, then everything works fine. If I place this call say inside a button listener.
settingsButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new PostToOpenFeint.execute();
}
});
在onPostExecute()不会被调用,不知道我做错了。我读的限制是从UI线程调用此,我从UI线程调用它。
The onPostExecute() never gets called, not sure what I am doing wrong. The restriction I read was to call this from UI Thread and I am calling it from UI thread.
我有一个类似的问题刚才。我被延长的AsyncTask&LT;整数,整数,整数GT;
和我onPostExecute方法看起来像:
I had a similiar problem just now. I was extending AsyncTask<Integer,Integer,Integer>
and my onPostExecute method looked like:
protected void onPostExecute(int result)
这似乎确定了我,但话又说回来,我更多的是.NET的家伙不是一个Java的家伙。 我把它改为:
This seemed OK to me, but then again I'm more of a .NET guy than a Java guy. I changed it to:
protected void onPostExecute(Integer result)
因为某种原因的Java认为有间 INT
的差异和整数
?
我觉得你的问题是,你声明的返回类型为无效
在
I think that your problem is that you're declaring the return type as void
in your:
extends<Void,Void,Void>
这意味着没有参数,可以没有任何进展,也没有结果。如果你想要执行的东西,当它这样做,我认为你需要给它某种价值像和整数或布尔值。
That means no params, no progress and no result. If you want to execute something when it's done, I think you need to give it some kind of value like and integer or a boolean.
如果您更改扩展到:
<Void,Void,Integer>
现在你的传球没有参数,可以不发布任何进展,但返回的值。改变你的 onPostExecute
的方法来接受整数
:
Now your passing no params, not publishing any progress, but are returning a value. Change your onPostExecute
method to accept an Integer
:
protected void onPostExecute(Integer result)
则返回在 doInBackground
方法更改为类似:
return 1;
那么就应该为您执行。
Then it should execute for you.
上一篇:在Android的扩展ArrayAdapterAndroid、ArrayAdapter
下一篇:谷歌地图Android的API提供了一个的NoClassDefFoundError地图、Android、NoClassDefFoundError、API