android-asynctask

Update UI from an AsyncTaskLoader

时间秒杀一切 提交于 2020-01-01 03:21:10
问题 I've converted my AsyncTask to an AsyncTaskLoader (mostly to deal with configuration changes). I have a TextView I am using as a progress status and was using onProgressUpdate in the AsyncTask to update it. It doesn't look like AsyncTaskLoader has an equivalent, so during loadInBackground (in the AsyncTaskLoader ) I'm using this: getActivity().runOnUiThread(new Runnable() { public void run() { ((TextView)getActivity().findViewById(R.id.status)).setText("Updating..."); } }); I am using this in

Lock orientation until Asynctask finish

a 夏天 提交于 2020-01-01 02:34:10
问题 Only want to block orientation until all the data is loaded in my view. So I thought about the following code but it doesn't work. private class task extends AsyncTask<String, Void, String> { protected String doInBackground(String... params) { ... } protected void onPostExecute(String result) { ... setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } protected void onPreExecute() { ... setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); } } When I run these two

How can I make a ProgressDialog be cancelable by the back button but not by a screen tap?

徘徊边缘 提交于 2019-12-31 11:29:24
问题 I would like to make a ProgressDialog cancelable by the back button but not by a screen tap. Currently I use setCancelable(true) . However, in some newer devices a tap on the screen also cancels the ProgressDialog . I'd like to disable the screen tap action while the ProgressDialog is shown. 回答1: Use setCanceledOnTouchOutside(false). 回答2: Try this it will help you: ProgressDialog pd = ProgressDialog.show(main.this, "", "Loading. Please wait...", true); pd.setCancelable(true);` 来源: https:/

Fragments being replaced while AsyncTask is executed - NullPointerException on getActivity()

China☆狼群 提交于 2019-12-31 10:34:08
问题 I recently converted my Activities to Fragments. Using something similar to Tab-Navigation the fragments are replaced when the user selects another tab. After the fragment is populated I start at least one AsyncTask to get some information from the internet. However - if the user switches to another tab just as the doBackground-method from my AsyncTask is being executed - the fragment is replaced and thus I am getting a NullPointerException in the marked lines: @Override protected Object

parallel execution of AsyncTask

拈花ヽ惹草 提交于 2019-12-31 07:01:26
问题 An AsyncTask is executed on click: List<RSSItem> list = new Vector<RSSItem>(); private OnClickListener click = new OnClickListener() { public void onClick(View view) { list.clear(); if((dft.getStatus().toString()).equals("RUNNING")) dft.cancel(true); currentCategory = catigoriesHolder.indexOfChild(view); dft = new DownloadFilesTask(); dft.execute(rssFeedURL[currentCategory]); } }; In doInBackGround method the variable list is filled up. How to prevent the list to be cleared at point at which

How to load more items in a ListView using AsyncTask or any other method

僤鯓⒐⒋嵵緔 提交于 2019-12-31 05:58:14
问题 I am very new to android development and I know that this question might be answer before but I can't seem to find a suitable answer for my situation. I am creating an android app which have a ListView to show list of items. I need to show more items (like 10 more items) when the user reaches the footer of the ListView . I have implemented the setOnScrollListener() . My only issue and for which I need your guidance is that how can I get more items when the user reaches the bottom of the

Progress dialog and AsyncTask error

久未见 提交于 2019-12-31 05:31:06
问题 I'm a bit new with the AsyncTask and ProgressDialog and i'm getting a null pointer exception error whenever i call new MyTask().execute(); on my button does my approach is not right? what is wrong with my code or what am i missing? The process only it should process depends on the current TabHost selected so.. Here is my code: public class MyTask extends AsyncTask<Void, Integer, Void>{ @Override protected void onPreExecute() { //Show progress Dialog here super.onPreExecute(); progress.show();

already use AsyncTask doInBackground but the new data not show up

倾然丶 夕夏残阳落幕 提交于 2019-12-31 05:28:09
问题 I make a chat room with AsyncTask for receive messages, so it always checking the coming messages and show it to client, but the code seems not works what i hope. in client only show all old datas, for the new datas not show up. because when I try to send messages from server, the new data didn't show in client. I got confused with this problem, and really need help. anyone please help me, thank you. AsyncTask for receive public class ReceivedTask extends AsyncTask<String, String, String> {

Why doesn't mocking work with AsyncTask?

为君一笑 提交于 2019-12-31 04:48:27
问题 I'm testing an Android app using an ApplicationTestCase. I want to mock one of my AsyncTasks (example simplified to show the problem): public class Foo extends AsyncTask<Void,Void,Void> { @Override protected Void doInBackground(Void... unused) { return null; } } So to set up my tests, I did the following: private Foo mockFoo; @Override protected void setUp() throws Exception { super.setUp() mockFoo = mock(Foo.class); createApplication(); } And then the actual test is the following: public

How to return an object from the asynctask to the main class in android

送分小仙女□ 提交于 2019-12-31 04:03:06
问题 I want to return the document to my main class but even using a global variable dosen't work it's because the asynctask didn't finish the job I think is there a solution to get an object form asynctask please ? I already tried the affectation in the onPostExecute but the object get null if i'm outside the asynctask this is the class : private class RequestTask extends AsyncTask<String, Void, Document> { protected Document doInBackground(String... url) { try { HttpClient httpClient = new