android-asynctask

Start new Activity outside the Activity context.

三世轮回 提交于 2021-02-19 01:39:11
问题 I tried to start an Activity and close other in my AsyncTask class ( onPostExecute() ). My code : Intent i = new Intent(parentActivity, ThunderHunter.class); c.startActivity(i); parentActivity.finish(); But it doesn't work, logcat shows : 08-01 18:01:27.640: E/AndroidRuntime(12398): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? 08-01 18:01:27.640: E/AndroidRuntime(12398)

Displaying RSS Feed on a fragment [duplicate]

霸气de小男生 提交于 2021-02-08 12:01:22
问题 This question already has answers here : What is a NullPointerException, and how do I fix it? (12 answers) Closed 2 years ago . I've created an app with a drawer menu that opens a new fragment for each menu option. Within those fragments i'm attempting run several functions. I've parsed an RSS feed, and want to display the information I've parsed on a ListView inside a specific fragment. My main activity navigates to the fragment no problem but gets stuck with a Null Pointer exception. This

Avoid App crashing when catch Exception

喜夏-厌秋 提交于 2021-02-08 10:42:53
问题 I have an internet operation that reads line from an online file. It is in a try-catch block. When the execution fails (for example for the missing internet connection) the operation go to catch block and the App crashes. How can I avoid crashes? try { BufferedReader reader = new BufferedReader(new InputStreamReader((new URL(MegaMethods.url+params[0])).openStream()), 8192); String line; while ((line = reader.readLine()) != null) { count++; } reader.close(); } catch (Exception e){ // Here I

An error occurred while executing doInBackground() for keyclock authService.performTokenRequest() function

左心房为你撑大大i 提交于 2021-02-08 10:38:46
问题 While integrating Keyclock SDK , I try to exchange authorization code to access token authService.performTokenRequest( resp.createTokenExchangeRequest(), new AuthorizationService.TokenResponseCallback() { @Override public void onTokenRequestCompleted( TokenResponse resp, AuthorizationException ex) { if (resp != null) { // exchange succeeded } else { // authorization failed, check ex for more details } } }); I got the following error, java.lang.RuntimeException: An error occurred while

How to wait for two Async HTTP request complete with loopj HTTP library

拈花ヽ惹草 提交于 2021-02-08 05:20:24
问题 My case is that I need to get two sets of data from sever with two HTTP get request, then process them together. I'm using loopj's http library to do the task. The problem is that since loopj's http is Async, which means I can't determine when they will be complete and which will complete first.They all have their own onSuccess function. I tried to put a boolean flag into each of them, and make the calling activity check the change of AND operation of these two boolean, but seems if I make

android - Updating ListView from AsyncTask called from custom adapter class

此生再无相见时 提交于 2021-02-07 10:30:25
问题 I am trying to update a ListView from an AsyncTask. I have this situation: Activity Class creates the list adapter from a custom Adapter class. Adapter class sets onClickListener on element from list item, and calls an AsyncTask located in a different Utilities class. How can I call notifyDataSetChanged from onPostExecute() method in the Utilities AsyncTask? 回答1: Include a Delegate as a callback to activate the refresh from within the original class. For example, add this interface: public

POST with Android Retrofit

谁都会走 提交于 2021-02-06 14:58:28
问题 I'm new to Android programming and working with Retrofit. I've done a bunch of research on this topic, but haven't been able to find a solution specific to my needs. I'm working with our API and trying to make a POST request. I successfully achieved this with the following non-Retrofit code: private class ProcessLogin extends AsyncTask<Void, String, JSONObject> { private ProgressDialog pDialog; String email,password; protected void onPreExecute() { super.onPreExecute(); inputEmail = (EditText

Should I call super.onPostExecute(result) in Android AsyncTask?

为君一笑 提交于 2021-02-06 14:21:20
问题 I wonder if it has any meaning to call super.onPostExecute(result) or super.onPreExecute in Android AsyncTask? I have been always calling them, but even in Android documentation about AsyncTask (Android API Reference: AsyncTask) they are omitted. So does it make any sense if I call them or not? 回答1: No, there is no need to call the superclass. If you take a look at the AsyncTask source, you will see that the super class does nothing: @SuppressWarnings({"UnusedDeclaration"}) protected void

Get JSON in AsyncTask Android

十年热恋 提交于 2021-02-04 14:08:12
问题 I'm trying to get JSON but I have to do it in AsyncTask , because I get this in logcat AndroidRuntime(18153): Caused by: android.os.NetworkOnMainThreadException . Here is my code: public class LatestAlbums extends Activity { TextView t; // url to make request private static String url = "www.example.com"; // JSON Node names private static final String TAG_ALBUMS = "albums"; private static final String TAG_ID = "id"; private static final String TAG_NAME = "name"; private static final String

How to solve the error : Only the original thread that created a view hierarchy can touch its views

橙三吉。 提交于 2021-01-29 11:15:18
问题 I'm not really familiar with the concept of threads , but I got this error showing up each time I'm trying to display my RecyclerView : Only the original thread that created a view hierarchy can touch its views. I'm retrieving data regarding some clients from the server , putting in it in an ArrayList and then displaying the data within a recyclerView . The data is retrieved within the method doInBackGround() Here is my Code : ClientList.java : public class ClientList extends