- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在更改屏幕方向时重新创建 Activity 、进度对话框和异步任务时遇到问题。我在这里看到了一些解决方案,我决定使用 onRetainCustomNonConfigurationInstance() 来保存 AsyncTask 的实例。好吧,在 onCreate 中我检查是否有 AsyncTask 的实例,如果存在,我会显示一个新的进度对话框。但是这个对话框在无限循环中阻塞了 UI(在 onPostExecute 中有 dialog.dismiss() )并且 Activity 当然不显示结果。
onCreate
getDirection = (GetDirection) getLastCustomNonConfigurationInstance();
if(getDirection != null) {
dialog = new ProgressDialog(RouteActivity.this);
dialog.setMessage(getResources().getString(R.string.loading_data));
dialog.setIndeterminate(false);
dialog.setCancelable(false);
dialog.show();
} else {
getDirection = new GetDirection();
getDirection.execute();
}
onRetainCustomNonConfigurationInstance
@Override
public Object onRetainCustomNonConfigurationInstance() {
return getDirection;
}
@Override
protected void onDestroy() {
super.onDestroy();
if (dialog.isShowing()) {
dialog.dismiss();
}
}
编辑#1:我采用了 Kingfisher with Fragment 和 Retained Fragment 的解决方案,但是当我在 AsyncTask 的 doInBackground 期间更改方向时,Expandable Listview 上有一个 NPE。
08-14 12:50:40.866: E/AndroidRuntime(22739): FATAL EXCEPTION: main
08-14 12:50:40.866: E/AndroidRuntime(22739): java.lang.NullPointerException
08-14 12:50:40.866: E/AndroidRuntime(22739): at com.pasquini.adapter.ListRouteExpandableAdapter.getGroupCount(ListRouteExpandableAdapter.java:78)
08-14 12:50:40.866: E/AndroidRuntime(22739): at android.widget.ExpandableListConnector.getCount(ExpandableListConnector.java:399)
08-14 12:50:40.866: E/AndroidRuntime(22739): at android.widget.ListView.setAdapter(ListView.java:460)
08-14 12:50:40.866: E/AndroidRuntime(22739): at android.widget.ExpandableListView.setAdapter(ExpandableListView.java:470)
08-14 12:50:40.866: E/AndroidRuntime(22739): at com.pasquini.activity.RouteActivity.onPostExecute(RouteActivity.java:792)
08-14 12:50:40.866: E/AndroidRuntime(22739): at com.pasquini.fragment.GetDirectionFragment$GetDirectionTask.onPostExecute(GetDirectionFragment.java:244)
08-14 12:50:40.866: E/AndroidRuntime(22739): at com.pasquini.fragment.GetDirectionFragment$GetDirectionTask.onPostExecute(GetDirectionFragment.java:1)
08-14 12:50:40.866: E/AndroidRuntime(22739): at android.os.AsyncTask.finish(AsyncTask.java:631)
08-14 12:50:40.866: E/AndroidRuntime(22739): at android.os.AsyncTask.access$600(AsyncTask.java:177)
08-14 12:50:40.866: E/AndroidRuntime(22739): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
08-14 12:50:40.866: E/AndroidRuntime(22739): at android.os.Handler.dispatchMessage(Handler.java:99)
08-14 12:50:40.866: E/AndroidRuntime(22739): at android.os.Looper.loop(Looper.java:137)
08-14 12:50:40.866: E/AndroidRuntime(22739): at android.app.ActivityThread.main(ActivityThread.java:4895)
08-14 12:50:40.866: E/AndroidRuntime(22739): at java.lang.reflect.Method.invokeNative(Native Method)
08-14 12:50:40.866: E/AndroidRuntime(22739): at java.lang.reflect.Method.invoke(Method.java:511)
08-14 12:50:40.866: E/AndroidRuntime(22739): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
08-14 12:50:40.866: E/AndroidRuntime(22739): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
08-14 12:50:40.866: E/AndroidRuntime(22739): at dalvik.system.NativeStart.main(Native Method).
这里是Fragment中的代码:
public class GetDirectionFragment extends Fragment {
private Map<Leg, List<Step>> legsCollection;
private ArrayList<Object> legsAndSteps;
private List<Leg> legs;
private List<Poi> pois;
private List<LatLng> polyz;
/**
* Callback interface through which the fragment will report the
* task's progress and results back to the Activity.
*/
public static interface TaskCallbacks {
void onPreExecute();
void onPostExecute();
List<Poi> getListPoiByRoute();
void setLegs(List<Leg> legs, Map<Leg, List<Step>> legsCollection);
void setPolyline(List<LatLng> polyz);
}
private TaskCallbacks callbacks;
private GetDirectionTask getDirectionTask;
/**
* Hold a reference to the parent Activity so we can report the
* task's current progress and results. The Android framework
* will pass us a reference to the newly created Activity after
* each configuration change.
*/
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
callbacks = (TaskCallbacks) activity;
} catch(ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement TaskCallbacks");
}
pois = callbacks.getListPoiByRoute();
}
/**
* This method will only be called once when the retained
* Fragment is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Retain this fragment across configuration changes.
setRetainInstance(true);
// Create and execute the background task.
getDirectionTask = new GetDirectionTask();
getDirectionTask.execute();
}
/**
* Set the callback to null so we don't accidentally leak the
* Activity instance.
*/
@Override
public void onDetach() {
super.onDetach();
callbacks = null;
}
private class GetDirectionTask extends AsyncTask<Void, Integer, Void> {
@Override
protected void onPreExecute() {
if (callbacks != null) {
callbacks.onPreExecute();
}
}
/**
* Note that we do NOT call the callback object's methods
* directly from the background thread, as this could result
* in a race condition.
*/
@Override
protected Void doInBackground(Void... ignore) {
List<String> lats = new ArrayList<String>();
List<String> longs = new ArrayList<String>();
for(Poi poi: pois) {
lats.add(poi.getCoordinates().getLatitude());
longs.add(poi.getCoordinates().getLongitude());
}
String stringUrl = "http://maps.googleapis.com/maps/api/directions/" +
"json?";
//if(actualLanguage.equals("en")) {
// stringUrl += "language=en_EN";
//} else {
stringUrl += "language=it";
//}
stringUrl+="&mode=walking&units=metric&origin=" +
lats.get(0) + "," +
longs.get(0);
stringUrl += "&destination=" +
lats.get(pois.size()-1) + "," +
longs.get(pois.size()-1) + "&" +
"waypoints=";
for(int i = 1; i<=lats.size()-2 && i<=longs.size()-2; i++) {
stringUrl += lats.get(i)+","+longs.get(i);
if(i==(lats.size()-2) && i==(longs.size()-2)) {
stringUrl += "&sensor=false";
} else {
stringUrl +="|";
}
}
Log.i("urlgoogle", stringUrl);
StringBuilder response = new StringBuilder();
try {
URL url = new URL(stringUrl);
HttpURLConnection httpconn = (HttpURLConnection) url
.openConnection();
if (httpconn.getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader input = new BufferedReader(
new InputStreamReader(httpconn.getInputStream()),
8192);
String strLine = null;
while ((strLine = input.readLine()) != null) {
response.append(strLine);
}
input.close();
}
String jsonOutput = response.toString();
JSONObject jsonObject = new JSONObject(jsonOutput);
// routesArray contains ALL routes
JSONArray routesArray = jsonObject.getJSONArray("routes");
// Grab the first route
JSONObject route = routesArray.getJSONObject(0);
JSONArray legsArray = route.getJSONArray("legs");
legs = new ArrayList<Leg>();
legsAndSteps = new ArrayList<Object>();
String htmlInstructions;
legsCollection = new LinkedHashMap<Leg, List<Step>>();
for(int i=0; i<legsArray.length(); i++) {
List<Step> steps = new ArrayList<Step>();
Leg leg = new Leg();
//int idLeg = 0;
JSONObject legJson = legsArray.getJSONObject(i);
leg.setDistance(legJson.getJSONObject("distance").getString("text"));
leg.setDuration(legJson.getJSONObject("duration").getString("text"));
leg.setEndAddress(legJson.getString("end_address"));
leg.setStartAddress(legJson.getString("start_address"));
leg.setIdLeg(pois.get(i).getId());
leg.setStartPoiName(pois.get(i).getName());
leg.setEndPoiName(pois.get(i+1).getName());
legsAndSteps.add(leg);
JSONArray stepsArray = legJson.getJSONArray("steps");
for(int j=0; j<stepsArray.length(); j++) {
Step step = new Step();
JSONObject stepJson = stepsArray.getJSONObject(j);
step.setDistance(stepJson.getJSONObject("distance").getString("text"));
step.setDuration(stepJson.getJSONObject("duration").getString("text"));
htmlInstructions = android.text.Html.fromHtml(stepJson.getString("html_instructions")).toString();
step.setInstructions(htmlInstructions);
//step.setIdLeg(idLeg);
//Aggiunto per Exp
steps.add(step);
legsAndSteps.add(step);
}
legsCollection.put(leg, steps);
legs.add(leg);
}
JSONObject poly = route.getJSONObject("overview_polyline");
String polyline = poly.getString("points");
polyz = decodePoly(polyline);
callbacks.setLegs(legs, legsCollection);
callbacks.setPolyline(polyz);
} catch (Exception e) {
}
return null;
}
@Override
protected void onPostExecute(Void ignore) {
if (callbacks != null) {
callbacks.onPostExecute();
}
}
}
/* Method to decode polyline points */
private List<LatLng> decodePoly(String encoded) {
[code...]
}
Activity 中的代码:
@Override
public void onPostExecute() {
expListView = (ExpandableListView) findViewById(R.id.lv_routepoi);
ListRouteExpandableAdapter expListAdapter = new ListRouteExpandableAdapter(
getApplicationContext(), legs, legsCollection);
expListView.setAdapter(expListAdapter);
setGroupIndicatorToRight();
expListView.setChildDivider(getResources().getDrawable(R.drawable.divider_route));
[code...]
dialog.dismiss();
}
@Override
public void setLegs(List<Leg> legs, Map<Leg, List<Step>> legsCollection) {
this.legs = legs;
this.legsCollection = legsCollection;
}
@Override
public void setPolyline(List<LatLng> polyz) {
this.polyz = polyz;
}
编辑 #2:我尝试了 Kingfisher 的新解决方案,但 doInBackground 方法中始终存在 NPE。如果我在加载期间不更改屏幕方向,应用程序不会崩溃并在 ListView 上显示数据。
08-14 17:27:44.897: I/AsyncTask(30604): java.lang.NullPointerException
08-14 17:27:44.897: E/AndroidRuntime(30604): FATAL EXCEPTION: main
08-14 17:27:44.897: E/AndroidRuntime(30604): java.lang.NullPointerException
08-14 17:27:44.897: E/AndroidRuntime(30604): at com.pasquini.activity.RouteActivity.onPostExecute(RouteActivity.java:847)
08-14 17:27:44.897: E/AndroidRuntime(30604): at com.pasquini.fragment.GetDirectionFragment$GetDirectionTask.onPostExecute(GetDirectionFragment.java:253)
08-14 17:27:44.897: E/AndroidRuntime(30604): at com.pasquini.fragment.GetDirectionFragment$GetDirectionTask.onPostExecute(GetDirectionFragment.java:1)
08-14 17:27:44.897: E/AndroidRuntime(30604): at android.os.AsyncTask.finish(AsyncTask.java:631)
08-14 17:27:44.897: E/AndroidRuntime(30604): at android.os.AsyncTask.access$600(AsyncTask.java:177)
08-14 17:27:44.897: E/AndroidRuntime(30604): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
08-14 17:27:44.897: E/AndroidRuntime(30604): at android.os.Handler.dispatchMessage(Handler.java:99)
08-14 17:27:44.897: E/AndroidRuntime(30604): at android.os.Looper.loop(Looper.java:137)
08-14 17:27:44.897: E/AndroidRuntime(30604): at android.app.ActivityThread.main(ActivityThread.java:4895)
08-14 17:27:44.897: E/AndroidRuntime(30604): at java.lang.reflect.Method.invokeNative(Native Method)
08-14 17:27:44.897: E/AndroidRuntime(30604): at java.lang.reflect.Method.invoke(Method.java:511)
08-14 17:27:44.897: E/AndroidRuntime(30604): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
08-14 17:27:44.897: E/AndroidRuntime(30604): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
08-14 17:27:44.897: E/AndroidRuntime(30604): at dalvik.system.NativeStart.main(Native Method)
这里是Fragment中的代码:
public class GetDirectionFragment extends Fragment {
private Map<Leg, List<Step>> legsCollection;
private ArrayList<Object> legsAndSteps;
private List<Leg> legs;
private List<Poi> pois;
private List<LatLng> polyz;
/**
* Callback interface through which the fragment will report the
* task's progress and results back to the Activity.
*/
public static interface TaskCallbacks {
void onPreExecute();
void onPostExecute();
List<Poi> getListPoiByRoute();
void setLegs(List<Leg> legs, Map<Leg, List<Step>> legsCollection);
void setPolyline(List<LatLng> polyz);
}
private TaskCallbacks callbacks;
private GetDirectionTask getDirectionTask;
/**
* Hold a reference to the parent Activity so we can report the
* task's current progress and results. The Android framework
* will pass us a reference to the newly created Activity after
* each configuration change.
*/
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
callbacks = (TaskCallbacks) activity;
} catch(ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement TaskCallbacks");
}
pois = callbacks.getListPoiByRoute();
}
/**
* This method will only be called once when the retained
* Fragment is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Retain this fragment across configuration changes.
setRetainInstance(true);
// Create and execute the background task.
getDirectionTask = new GetDirectionTask();
getDirectionTask.execute();
}
/**
* Set the callback to null so we don't accidentally leak the
* Activity instance.
*/
@Override
public void onDetach() {
super.onDetach();
callbacks = null;
}
private class GetDirectionTask extends AsyncTask<Void, Integer, Void> {
@Override
protected void onPreExecute() {
if (callbacks != null) {
callbacks.onPreExecute();
}
}
/**
* Note that we do NOT call the callback object's methods
* directly from the background thread, as this could result
* in a race condition.
*/
@Override
protected Void doInBackground(Void... ignore) {
List<String> lats = new ArrayList<String>();
List<String> longs = new ArrayList<String>();
for(Poi poi: pois) {
lats.add(poi.getCoordinates().getLatitude());
longs.add(poi.getCoordinates().getLongitude());
}
String stringUrl = "http://maps.googleapis.com/maps/api/directions/" +
"json?";
//if(actualLanguage.equals("en")) {
// stringUrl += "language=en_EN";
//} else {
stringUrl += "language=it";
//}
stringUrl+="&mode=walking&units=metric&origin=" +
lats.get(0) + "," +
longs.get(0);
stringUrl += "&destination=" +
lats.get(pois.size()-1) + "," +
longs.get(pois.size()-1) + "&" +
"waypoints=";
for(int i = 1; i<=lats.size()-2 && i<=longs.size()-2; i++) {
stringUrl += lats.get(i)+","+longs.get(i);
if(i==(lats.size()-2) && i==(longs.size()-2)) {
stringUrl += "&sensor=false";
} else {
stringUrl +="|";
}
}
Log.i("urlgoogle", stringUrl);
StringBuilder response = new StringBuilder();
try {
URL url = new URL(stringUrl);
HttpURLConnection httpconn = (HttpURLConnection) url
.openConnection();
if (httpconn.getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader input = new BufferedReader(
new InputStreamReader(httpconn.getInputStream()),
8192);
String strLine = null;
while ((strLine = input.readLine()) != null) {
response.append(strLine);
}
input.close();
}
String jsonOutput = response.toString();
JSONObject jsonObject = new JSONObject(jsonOutput);
// routesArray contains ALL routes
JSONArray routesArray = jsonObject.getJSONArray("routes");
// Grab the first route
JSONObject route = routesArray.getJSONObject(0);
JSONArray legsArray = route.getJSONArray("legs");
legs = new ArrayList<Leg>();
legsAndSteps = new ArrayList<Object>();
String htmlInstructions;
legsCollection = new LinkedHashMap<Leg, List<Step>>();
for(int i=0; i<legsArray.length(); i++) {
List<Step> steps = new ArrayList<Step>();
Leg leg = new Leg();
//int idLeg = 0;
JSONObject legJson = legsArray.getJSONObject(i);
leg.setDistance(legJson.getJSONObject("distance").getString("text"));
leg.setDuration(legJson.getJSONObject("duration").getString("text"));
leg.setEndAddress(legJson.getString("end_address"));
leg.setStartAddress(legJson.getString("start_address"));
leg.setIdLeg(pois.get(i).getId());
leg.setStartPoiName(pois.get(i).getName());
leg.setEndPoiName(pois.get(i+1).getName());
legsAndSteps.add(leg);
JSONArray stepsArray = legJson.getJSONArray("steps");
for(int j=0; j<stepsArray.length(); j++) {
Step step = new Step();
JSONObject stepJson = stepsArray.getJSONObject(j);
step.setDistance(stepJson.getJSONObject("distance").getString("text"));
step.setDuration(stepJson.getJSONObject("duration").getString("text"));
htmlInstructions = android.text.Html.fromHtml(stepJson.getString("html_instructions")).toString();
step.setInstructions(htmlInstructions);
//step.setIdLeg(idLeg);
steps.add(step);
legsAndSteps.add(step);
}
legsCollection.put(leg, steps);
legs.add(leg);
}
JSONObject poly = route.getJSONObject("overview_polyline");
String polyline = poly.getString("points");
polyz = decodePoly(polyline);
setLegs(legs, legsCollection);
setPolyline(polyz);
} catch (Exception e) {
Log.i(TAG, e.toString());
}
return null;
}
@Override
protected void onPostExecute(Void ignore) {
if (callbacks != null) {
callbacks.onPostExecute();
}
}
}
/* Method to decode polyline points */
private List<LatLng> decodePoly(String encoded) {
[code...]
}
public void setLegs(List<Leg> legs, Map<Leg, List<Step>> legsCollection) {
this.legs = legs;
this.legsCollection = legsCollection;
}
public void setPolyline(List<LatLng> polyz) {
this.polyz = polyz;
}
public List<Leg> getLegs() {
return this.legs;
}
public Map<Leg, List<Step>> getMap() {
return this.legsCollection;
}
public List<LatLng> getPolyline() {
return this.polyz;
}
Activity 中的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
[code...]
FragmentManager fm = getSupportFragmentManager();
getDirectionFragment = (GetDirectionFragment) fm.findFragmentByTag(TASK_FRAGMENT_TAG);
// If the Fragment is non-null, then it is currently being
// retained across a configuration change.
if (getDirectionFragment == null) {
getDirectionFragment = new GetDirectionFragment();
fm.beginTransaction().add(getDirectionFragment, TASK_FRAGMENT_TAG).commit();
[code...]
}
@Override
public void onPostExecute() {
legs = getDirectionFragment.getLegs();
legsCollection = getDirectionFragment.getMap();
polyz = getDirectionFragment.getPolyline();
expListView = (ExpandableListView) findViewById(R.id.lv_routepoi);
ListRouteExpandableAdapter expListAdapter = new ListRouteExpandableAdapter(
getApplicationContext(), legs, legsCollection);
expListView.setAdapter(expListAdapter);
setGroupIndicatorToRight();
expListView.setChildDivider(getResources().getDrawable(R.drawable.divider_route));
[code...]
}
最佳答案
检查此链接:Handling Configuration Changes with Fragments或者你可以使用 AsyncTaskLoader .我建议使用 Retained Fragment
来处理配置更改。仔细阅读文章。已编辑: 不要在 doInBackground
中调用 callback.set
函数。您应该在重新创建 Activity 时找到您的 Retained Fragment
,并在onPost函数
中尝试使用Retained Fragment
的get函数获取列表结果。
//Activity recreated
FragmentManager fm = getFragmentManager();
mTaskFragment = (TaskFragment) fm.findFragmentByTag("task");
//onPost method
yourList = mTaskFragment.getLegsAndMoveList();
// Do lisview data changing here
希望这对您有所帮助。
关于android - AsyncTask 和方向的改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18214293/
我今天在我的 Android 项目中遇到了一个涉及 aSyncTasks 的问题,经过一些研究找到了答案,并且与我交谈过的人都没有意识到,所以我想我会与 SO 社区分享,以防万一有人发现它有任何用处。
我目前正在 AsyncTask 的 onPostExecute 方法中执行类似的操作,其中 NewTask 不是当前正在执行的任务: private class OlderTask extends A
所以,我正在研究一个条形码解码器,一旦我们有了条形码,它就会通过互联网进入多个 API 来解码刚刚扫描的内容。问题是我必须将一些 XML 解析链接在一起,我不知道我做的是否正确。 因此,扫描条形码后,
我的团队开发了一个新的 Android 应用程序,它广泛使用了 Room。 我不确定我们是否正确使用 AsyncTask。 我们不得不在 AsyncTasks 中包装所有对 insert/update
我查看了其他问题,但未能澄清我对从另一个任务调用任务的疑问,我有以下代码: protected List doInBackground(String... params) try {
我正在开发一个访问 Web 服务的应用程序,并使用从中获取的 JSON 创建一个对象并在我的代码中使用它。尽管我的应用程序正在运行,但我不知道它是否写得很好且完美无缺。 我将解释我的内容,然后放置一些
虽然我还没有尝试过,但从理论上讲,我问这个问题只是为了消除我的疑虑。 我有这样一个场景:1. 向服务器发送请求并接收 JSON 响应。为此,我正在使用 AsyncTask,因为接收响应可能会有延迟。2
我有以下 AsyncTask 的实现,允许多个 AsyncTask 同时运行: public abstract class MyAsyncTask extends AsyncTask { pu
花了很多时间试图解决这个问题,我已经阅读了很多问题、论坛、答案......但它仍然不会更新 UI。 我的最终目标是从用户那里获取一个搜索词,并将一个 httprequest 发送到用 JSON 回复的
我有一个异步任务 private class LoadData extends AsyncTask { private String WEBURL; LoadData(String u
我正在用 android 做一些编码工作。我几乎遇到了一个问题,为了解决这个问题,我需要一个匿名 AsyncTask 类来执行。但我还需要在执行之前传递并反对这个类。我尝试了下面的代码,但它不起作用,
我有两个 AsyncTask:第一个寻找素数,如果成功,我必须调用第二个 AsyncTask 显示单词“Yop!” (将这个词添加到数组列表中,并显示在AsyncTask三)。 如果我从 onProg
我想使用 AsyncTask 将图像加载到 ListView。 private class LoadImageTask extends AsyncTask,Void,Bitmap>{ @Sup
在我的 AsyncTask 的某个时刻,在完成一些验证之后,我需要派生另一个线程来做一些其他工作。所以我现在想要两个后台线程,每个都做自己的事情(每个执行大约 2-3 秒)。我们的想法是最大限度地提高
(这与空指针无关):我在 AsyncTask 中有一个进度条,并且添加了一个取消按钮来取消 asynctask。 我可以从异步任务外部取消异步任务,但我需要在异步任务下实现的progressdialo
我有一个 Activity ,在启动时调用“json”来获取歌曲的数据类别,之后我调用方法“AsyncTask”来获取来自另一个“JSON”的歌曲列表问题是,当我启动 Activity 时,它被锁定,
我想做以下事情。我想显示一个包含信息和图像的列表。这些图像需要一段时间才能加载,所以我想我会采取不同的方式。我会使用两个 AsyncTasks。第一个创建所有布局并用除图像之外的数据填充它。第二个只是
如果我做了这样的事情: public class MyFragment extends Fragment { private GetDataTask mGDT; //onCreat
在 Android Activity 中,我在 onCreate 方法中执行 AsyncTask。我应该在 AsyncTask 的 onPostExecute 中还是在 OnCreate 方法中声明
我对 AsyncTask 有疑问我尝试为 10 个 Json 文件向互联网打开 10 个请求,因此我读取它并将其保存到用户设备_由于数据差异,此文件必须分开,包括。 那么,将每个请求放在单个 Asyn
我是一名优秀的程序员,十分优秀!