- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在这里,我使用 AsyncTask
在具有 TabLayout
和 ViewPager
的嵌套 fragment 中调用 Web 服务。我已经通过在每个 Fragment
的 onResume
方法中调用它们来尝试 AsyncTasks
作为:
new FetchAllData(getActivity()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
和
new FetchAllData(getActivity()).execute();
一切都很好,但我遇到了很多问题:
应用程序在没有任何对话框的情况下停止工作,但它在 logcat 中显示suspending all threads
。
当我们从图像中显示的另一个 Activity 访问此 fragment (具有嵌套的 tablayouts 和 viewpager)时,除工具栏外,其他所有内容都会空白 3 到 5 秒。突然之间,他们带来了完整的数据。
当我们从同一 Activity 的另一个 fragment 调用此 fragment 时,它会卡住在那里,而这个 fragment 会突然在那里打开。
我希望你能解决我所有的问题,如果没有请告诉我。
堆栈跟踪是:
1-29 12:10:49.580 10853-10863/com.cws.advisorymandi W/art: Suspending all threads took: 10.409ms
01-29 12:10:49.707 10853-10853/com.cws.advisorymandi D/cr_Ime: [InputMethodManagerWrapper.java:27] Constructor
01-29 12:10:49.711 10853-10853/com.cws.advisorymandi D/cr_Ime: [ImeAdapter.java:241] attach
01-29 12:10:49.711 10853-10853/com.cws.advisorymandi W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-29 12:10:49.716 10853-10853/com.cws.advisorymandi W/AwContents: onDetachedFromWindow called when already detached. Ignoring
01-29 12:10:49.717 10853-10853/com.cws.advisorymandi D/cr_Ime: [InputMethodManagerWrapper.java:56] isActive: false
01-29 12:10:49.726 10853-10853/com.cws.advisorymandi W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-29 12:10:49.726 10853-10853/com.cws.advisorymandi W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-29 12:10:49.812 10853-10853/com.cws.advisorymandi D/cr_Ime: [ImeAdapter.java:241] attach
01-29 12:10:49.832 10853-10853/com.cws.advisorymandi D/cr_Ime: [ImeAdapter.java:241] attach
01-29 12:10:49.833 10853-10853/com.cws.advisorymandi I/Choreographer: Skipped 58 frames! The application may be doing too much work on its main thread.
01-29 12:10:50.075 10853-10853/com.cws.advisorymandi W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 10853
01-29 12:10:50.610 10853-10863/com.cws.advisorymandi W/art: Suspending all threads took: 43.636ms
01-29 12:10:50.621 10853-10853/com.cws.advisorymandi I/Ads: Scheduling ad refresh 60000 milliseconds from now.
01-29 12:10:50.630 10853-10853/com.cws.advisorymandi I/Ads: Ad finished loading.
fragment .java
public class IndicesFragment extends android.support.v4.app.Fragment implements SwipeRefreshLayout.OnRefreshListener {
public static String imagepath = null;
public static FetchAllData myTask;
static ArrayList<EquityDetails> catListDao = new ArrayList<EquityDetails>();
static ArrayList<EquityDetails> catListDao1 = new ArrayList<EquityDetails>();
static int count = 0;
static int count1 = 0;
ListView list;
ImageView progressBar;
View view;
Activity act;
AdvisorsAdapter adapter;
TextView empty_text;
AnimatorSet set;
JSONArray jsonArray;
SwipeRefreshLayout swipeRefreshLayout;
private boolean isViewShown = false;
public static IndicesFragment newInstance() {
return new IndicesFragment();
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
isViewShown = true;
if (adapter != null) {
adapter.filter("");
}
} else {
isViewShown = false;
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.equity_activity, container, false);
act = this.getActivity();
Constants.check_fragment_visible = 1;
count++;
setHasOptionsMenu(true);
list = (ListView) view.findViewById(R.id.list_equity);
empty_text = (TextView) view.findViewById(R.id.empty);
swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
progressBar = (ImageView) view.findViewById(R.id.progressBar);
set = (AnimatorSet) AnimatorInflater.loadAnimator(getActivity(), R.animator.fadein);
set.setTarget(progressBar);
progressBar.setVisibility(View.GONE);
if (Utils.isNetworkAvailable(getActivity())) {
if (catListDao.size() > 0) {
adapter = new AdvisorsAdapter(act, R.layout.custom_equity, catListDao, 0);
list.setAdapter(adapter);
} else {
if (!isViewShown) {
new FetchAllData(getActivity(), 3).execute();
}
}
} else {
CustomToast toast = new CustomToast(getActivity(), "There is no internet connection!");
}
swipeRefreshLayout.setOnRefreshListener(this);
return view;
}
public void onActivityCreated(Bundle savedInstanceState1) {
super.onActivityCreated(savedInstanceState1);
}
@Override
public void onResume() {
super.onResume();
Constants.check_fragment_visible = 1;
if (Constants.check_reload) {
if (Utils.isNetworkAvailable(getActivity())) {
new FetchAllData(getActivity(), 3).execute();
} else {
CustomToast toast = new CustomToast(getActivity(), "There is no internet connection!");
}
}
if (adapter != null) adapter.notifyDataSetChanged();
}
@Override
public void onRefresh() {
if (Utils.isNetworkAvailable(getActivity())) {
new FetchAllData(getActivity(), 3).execute();
} else {
CustomToast toast = new CustomToast(getActivity(), "There is no internet connection!");
}
}
public void doChange(String queryText) {
if (queryText != null) {
if (adapter != null)
adapter.filter(queryText);
}
}
public void parseJSON(String result) {
if (result != null) {
JSONObject jsonObject;
try {
catListDao = new ArrayList<EquityDetails>();
jsonObject = new JSONObject(result);
jsonArray = jsonObject.getJSONArray("list");
Log.d("Length ", "" + jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++) {
EquityDetails allDirectory = new EquityDetails();
allDirectory.setEntry_value(jsonArray.getJSONObject(i).getString("entry"));
String value1 = jsonArray.getJSONObject(i).getString("entry");
String value2 = jsonArray.getJSONObject(i).getString("tgt_1");
allDirectory.setSerial_value(jsonArray.getJSONObject(i).getString("sl"));
allDirectory.setTg_value1(jsonArray.getJSONObject(i).getString("tgt_1"));
allDirectory.setTg_value2(jsonArray.getJSONObject(i).getString("tgt_2"));
allDirectory.setPosted_by(jsonArray.getJSONObject(i).getString("posted_by"));
allDirectory.setMainTitle_value(jsonArray.getJSONObject(i).getString("script"));
allDirectory.setMain_subTitle_value(jsonArray.getJSONObject(i).getString("exchange"));
allDirectory.setRating_value(jsonArray.getJSONObject(i).getString("rating"));
allDirectory.setReview_value(jsonArray.getJSONObject(i).getString("review"));
imagepath = jsonArray.getJSONObject(i).getString("advisor_image");
Log.d("Comminh Image ", "" + jsonArray.getJSONObject(i).getString("advisor_image"));
allDirectory.setImage1(jsonArray.getJSONObject(i).getString("advisor_image"));
allDirectory.setImage2(jsonArray.getJSONObject(i).getString("script_image"));
allDirectory.setBuy(jsonArray.getJSONObject(i).getString("buy_sentiment"));
allDirectory.setSell(jsonArray.getJSONObject(i).getString("sell_sentiment"));
allDirectory.setRecommend(jsonArray.getJSONObject(i).getString("recommendation"));
allDirectory.setPosted_date(jsonArray.getJSONObject(i).getString("posted_date"));
allDirectory.setCall_id(jsonArray.getJSONObject(i).getString("call_id"));
allDirectory.setExpiry_date(jsonArray.getJSONObject(i).getString("expiry_date"));
allDirectory.setBroker_name(jsonArray.getJSONObject(i).getString("name"));
allDirectory.setCall_detail(jsonArray.getJSONObject(i).getString("detail"));
allDirectory.setProgress_indicator(0);
catListDao.add(allDirectory);
}
catListDao1 = catListDao;
adapter = new AdvisorsAdapter(act, R.layout.custom_equity, catListDao, 0);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
public class FetchAllData extends AsyncTask<Void, Void, String> {
ProgressDialog pDialog;
int typeId;
private Context cont;
public FetchAllData(Context con, int typeId) {
// TODO Auto-generated constructor stub
this.cont = con;
this.typeId = typeId;
Log.d("Constructor Called", "yes");
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
if (!swipeRefreshLayout.isRefreshing()) {
if (progressBar != null) {
progressBar.setVisibility(View.VISIBLE);
set.start();
}
}
}
@Override
protected String doInBackground(Void... params) {
// TODO Auto-generated method stub
return getString();
}
private String getString() {
// TODO Auto-generated method stub
URL obj = null;
HttpURLConnection con = null;
try {
obj = new URL(Constants.AppBaseUrl + "/call_listing/" + typeId);
String userPassword = "rickmams" + ":" + "advisor11";
String header = "Basic " + new String(android.util.Base64.encode(userPassword.getBytes(), android.util.Base64.NO_WRAP));
con = (HttpURLConnection) obj.openConnection();
con.addRequestProperty("Authorization", header);
con.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
con.setRequestMethod("POST");
// For POST only - BEGIN
con.setDoOutput(true);
OutputStream os = con.getOutputStream();
os.flush();
os.close();
// For POST only - END
int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) { //success
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
Log.i("TAG", response.toString());
parseJSON(response.toString());
return response.toString();
} else {
Log.i("TAG", "POST request did not work.");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (con != null) {
con.disconnect();
}
}
return null;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if (getActivity() == null)
return;
if (swipeRefreshLayout.isRefreshing()) {
swipeRefreshLayout.setRefreshing(false);
}
if (result != null) {
if (progressBar != null) {
list.setAdapter(adapter);
//pDialog.dismiss();
if (progressBar != null) {
set.end();
if (progressBar.getVisibility() == View.VISIBLE)
progressBar.setVisibility(View.GONE);
}
if (jsonArray.length() != 0) {
empty_text.setVisibility(View.GONE);
} else empty_text.setVisibility(View.VISIBLE);
}
}
}
}
}
要获得完整的堆栈跟踪信息,请访问 http://pastebin.com/7FDynA05
最佳答案
我知道我来晚了,但当我看到你关于应用程序处理的很多问题时,我发现没有任何错误,但我仍然想说请检查你是否正在调用任何 TypeFace
每次都创建一个新对象,因此对它们进行注释并运行您的代码。
关于android - 在嵌套 fragment 中运行多个 AsyncTasks 时挂起线程,这会使应用变慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35054425/
尝试使用集成到 QTCreator 的表单编辑器,但即使我将插件放入 QtCreator.app/Contents/MacOS/designer 也不会显示。不过,相同的 dylib 文件确实适用于独
在此代码示例中。 “this.method2();”之后会读到什么?在返回returnedValue之前会跳转到method2()吗? public int method1(int returnedV
我的项目有通过gradle配置的依赖项。我想添加以下依赖项: compile group: 'org.restlet.jse', name: 'org.restlet.ext.apispark', v
我将把我们基于 Windows 的客户管理软件移植到基于 Web 的软件。我发现 polymer 可能是一种选择。 但是,对于我们的使用,我们找不到 polymer 组件具有表格 View 、下拉菜单
我的项目文件夹 Project 中有一个文件夹,比如 ED 文件夹,当我在 Eclipse 中指定在哪里查找我写入的文件时 File file = new File("ED/text.txt"); e
这是奇怪的事情,这个有效: $('#box').css({"backgroundPosition": "0px 250px"}); 但这不起作用,它只是不改变位置: $('#box').animate
这个问题在这里已经有了答案: Why does OR 0 round numbers in Javascript? (3 个答案) 关闭 5 年前。 Mozilla JavaScript Guide
这个问题在这里已经有了答案: Is the function strcmpi in the C standard libary of ISO? (3 个答案) 关闭 8 年前。 我有一个问题,为什么
我目前使用的是共享主机方案,我不确定它使用的是哪个版本的 MySQL,但它似乎不支持 DATETIMEOFFSET 类型。 是否存在支持 DATETIMEOFFSET 的 MySQL 版本?或者有计划
研究 Seam 3,我发现 Seam Solder 允许将 @Named 注释应用于包 - 在这种情况下,该包中的所有 bean 都将自动命名,就好像它们符合条件一样@Named 他们自己。我没有看到
我知道 .append 偶尔会增加数组的容量并形成数组的新副本,但 .removeLast 会逆转这种情况并减少容量通过复制到一个新的更小的数组来改变数组? 最佳答案 否(或者至少如果是,则它是一个错
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
noexcept 函数说明符是否旨在 boost 性能,因为生成的对象中可能没有记录异常的代码,因此应尽可能将其添加到函数声明和定义中?我首先想到了可调用对象的包装器,其中 noexcept 可能会产
我正在使用 Angularjs 1.3.7,刚刚发现 Promise.all 在成功响应后不会更新 angularjs View ,而 $q.all 会。由于 Promises 包含在 native
我最近发现了这段JavaScript代码: Math.random() * 0x1000000 10.12345 10.12345 >> 0 10 > 10.12345 >>> 0 10 我使用
我正在编写一个玩具(物理)矢量库,并且遇到了 GHC 坚持认为函数应该具有 Integer 的问题。是他们的类型。我希望向量乘以向量以及标量(仅使用 * ),虽然这可以通过仅使用 Vector 来实现
PHP 的 mail() 函数发送邮件正常,但 Swiftmailer 的 Swift_MailTransport 不起作用! 这有效: mail('user@example.com', 'test
我尝试通过 php 脚本转储我的数据,但没有命令行。所以我用 this script 创建了我的 .sql 文件然后我尝试使用我的脚本: $link = mysql_connect($host, $u
使用 python 2.6.4 中的 sqlite3 标准库,以下查询在 sqlite3 命令行上运行良好: select segmentid, node_t, start, number,title
我最近发现了这段JavaScript代码: Math.random() * 0x1000000 10.12345 10.12345 >> 0 10 > 10.12345 >>> 0 10 我使用
我是一名优秀的程序员,十分优秀!