安卓的AsyncTask传递一个字符串 [英] Android Asynctask passing a single string
本文介绍了安卓的AsyncTask传递一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想传递一个字符串转换为AsyncTask的。谁能告诉我它是怎么做的?我getEntity需要的方法getEntity(活动,字符串,EntityGetListener),但我一直在通过此String []
字符串传递= story.get(位置).getEntity();
新RemoteDataTask()执行(通过)。
私有类RemoteDataTask扩展的AsyncTask<字符串,字符串,龙> {
@覆盖
保护龙doInBackground(字符串... PARAMS){
// TODO自动生成方法存根
EntityUtils.getEntity(活动,PARAMS,新EntityGetListener(){
@覆盖
公共无效使用onGET(实体实体){
观看次数= entity.getEntityStats()getViews()。
}
@覆盖
公共无效onerror的(SocializeException错误){
}
});
返回null;
}
}
解决方案
您已经有这个
新RemoteDataTask()执行(通过)。 //假设通是一个字符串
在 doInbackground
@覆盖
保护龙doInBackground(字符串... PARAMS){
字符串s = PARAMS [0]; //这里是您选择的字符串
... //的code休息。
}
您可以找到@
详细信息<一个href="http://developer.android.com/reference/android/os/AsyncTask.html">http://developer.android.com/reference/android/os/AsyncTask.html
I would like to pass a single string into an asynctask. Could anyone show me how it is done? my getEntity needs The method getEntity(Activity, String, EntityGetListener) but I keep passing this String[]
String pass= story.get(position).getEntity();
new RemoteDataTask().execute(pass);
private class RemoteDataTask extends AsyncTask<String, String, Long> {
@Override
protected Long doInBackground(String... params) {
// TODO Auto-generated method stub
EntityUtils.getEntity(activity, params, new EntityGetListener() {
@Override
public void onGet(Entity entity) {
viewcount = entity.getEntityStats().getViews();
}
@Override
public void onError(SocializeException error) {
}
});
return null;
}
}
解决方案
You already have this
new RemoteDataTask().execute(pass); // assuming pass is a string
In doInbackground
@Override
protected Long doInBackground(String... params) {
String s = params[0]; // here's youre string
... //rest of the code.
}
You can find more info @
http://developer.android.com/reference/android/os/AsyncTask.html
这篇关于安卓的AsyncTask传递一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文