I'm using nearby connections to create a connection between devices. When a connection has been established, the activity is changed. Now if a device disconnects then a callback is called, but its received in the old activity. Now I want to show an AlertDialog, but the dialog is never shown because it shows on the old activity. How can show the dialog on the new activity?
I'm using nearby connections like this: URL
private Activity mActivity;
public RemoteConnection(Activity activity){
mActivity = activity;
}
// For simplicity I did only include this method
#Override
public void onDisconnected(String endpointId) {
// We've been disconnected from this endpoint. No more data can be
// sent or received.
new AlertDialog.Builder(mActivity)
.setTitle("Disconnection")
.setMessage("Other device is disconnected")
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
The dialog should be shown on the current activity
Write a method in your activities as:
public void showAlert(activity)
{
new AlertDialog.Builder(activity)
.setTitle("Disconnection")
.setMessage("Other device is disconnected")
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
and change following code :
#Override
public void onDisconnected(String endpointId) {
// We've been disconnected from this endpoint. No more data can be
// sent or received.
new AlertDialog.Builder(mActivity)
.setTitle("Disconnection")
.setMessage("Other device is disconnected")
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
To:
#Override
public void onDisconnected(String endpointId) {
// We've been disconnected from this endpoint. No more data can be
// sent or received.
if(((YourActivityA)activity) != null)
{
((YourActivityA)activity).showAlert(activity);
}
else if(((YourActivityB)activity) != null)
{
((YourActivityB)activity).showAlert(activity);
}
}
Use an event bus implementation or send the callback using sendBroadcast() and have each Activity register a BroadcastReceiver in onResume() and unregister it in onPause().
I have an adapter class that handles displaying a list of thumbnail images. When the user clicks on a thumbnail, it retrieves an image from a URL and takes about a second to do so and displays it in a dialog fragment. Because of the delay, I want there to be a toast that says "fetching image". However, the toast does not appear until the dialog fragment displays, which is pointless.
I have tried moving the toast before and after the call to make a dialog fragment and still the same result. I have tried using an AsyncTask to synchronize the toast first and then the dialog fragment but still the same result.
Adapter class:
holder.viewThumbnail.setOnClickListener(v ->
{
FetchImage fetchImage = new FetchImage(MainActivity.mainActivity, rootView, position);
fetchImage.execute();
});
FetchImage class:
protected final Void doInBackground(WeakReference<Activity>... params)
{
if(MainActivity.animalList.get(position).getImage() == null)
{
MainActivity mainActivity = weakReferenceActivity.get();
if(mainActivity != null)
{
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(mainActivity, mainActivity.getString(R.string.fetching_image), Toast.LENGTH_SHORT).show());
}
}
return null;
}
protected void onPostExecute(Void result)
{
super.onPostExecute(result);
MainActivity mainActivity = weakReferenceActivity.get();
if(mainActivity != null)
{
mainActivity.dialogShow(view, C.NO, C.DIALOG_IMAGE, "", "", position);
}
}
I also simply tried doing this in the adapter class without the AsyncTask route:
Adapter class:
holder.viewThumbnail.setOnClickListener(v ->
{
if(MainActivity.animalList.get(position).getImage() == null)
interfaceCommon.makeToast("fetching data", 1);
interfaceCommon.dialogShow(rootView, C.NO, C.DIALOG_IMAGE, "", "", position);
});
The interfaceCommon is simply a common interface to call methods in the Main Activity. I have one activity for this app and multiple fragments.
AM not so good in android Fragments. We need a proper solution to solve my problem. In mother activity I've fragment A,B,C. Every fragments comes after another . First A fragment is shown and after some user input we replace it with Fragment B and Fragment A is stacked. After B is done we replace it with C Fragment and B is stacked after A. I can go back to previous fragment to Edit the Data so we are saving the user inputs.
But when I go back to Fragments always I can get all data but only can update Fragment A UI view . I can't update any ui view in Fragment B and C .
Code snippests for different portions
abid hasan: getting current object for updating
City currentCity = cityManager.getCurrentCity();
updateViews(currentCity);
checking data for this object and updating views .
public static void updateViews(City currentCity){
Log.d(TAG , "updating views for city... "+currentCity.getCityName());
if (currentCity.getCityAccommodations().size() > 0 || currentCity.getCityLocations().size() > 0 || currentCity.getHotels().size() > 0) {
viewModifyLayoutHotels.setVisibility(View.VISIBLE);
deSelectAccommodationRadioButton.setChecked(false);
} else {
viewModifyLayoutHotels.setVisibility(View.GONE);
}
if (currentCity.cityFlights.size() > 0) {
viewModifyLayoutFlights.setVisibility(View.VISIBLE);
deSelectFlyRadioButton.setChecked(false);
} else {
viewModifyLayoutFlights.setVisibility(View.GONE);
}
if(currentCity.getFlightClass().equals("")){
viewModifyLayoutFlights.setVisibility(View.VISIBLE);
deSelectFlyRadioButton.setChecked(false);
}else {
viewModifyLayoutFlights.setVisibility(View.GONE);
}
if (currentCity.getActivities().size() > 0) {
viewModifyLayoutActivities.setVisibility(View.VISIBLE);
deSelectActivityRadioButton.setChecked(false);
} else {
viewModifyLayoutActivities.setVisibility(View.GONE);
}
}
on back press event from the successor fragment’s onDestroy() method and getting that object from manager and updating views
public static void updateViews(City currentCity){
Log.d(TAG , "updating views for city... "+currentCity.getCityName());
if (currentCity.getCityAccommodations().size() > 0 || currentCity.getCityLocations().size() > 0 || currentCity.getHotels().size() > 0) {
viewModifyLayoutHotels.setVisibility(View.VISIBLE);
deSelectAccommodationRadioButton.setChecked(false);
} else {
viewModifyLayoutHotels.setVisibility(View.GONE);
}
if (currentCity.cityFlights.size() > 0) {
viewModifyLayoutFlights.setVisibility(View.VISIBLE);
deSelectFlyRadioButton.setChecked(false);
} else {
viewModifyLayoutFlights.setVisibility(View.GONE);
}
if(currentCity.getFlightClass().equals("")){
viewModifyLayoutFlights.setVisibility(View.VISIBLE);
deSelectFlyRadioButton.setChecked(false);
}else {
viewModifyLayoutFlights.setVisibility(View.GONE);
}
if (currentCity.getActivities().size() > 0) {
viewModifyLayoutActivities.setVisibility(View.VISIBLE);
deSelectActivityRadioButton.setChecked(false);
} else {
viewModifyLayoutActivities.setVisibility(View.GONE);
}
}
before onDestroy() call I reset Those view to initial state from onStart() method
#Override
public void onStart() {
Log.d(MakeATripStepFourFragment.TAG , "calling onStart from "+TAG);
MakeATripFragmentFirstTime.destinationTextView.setText("Select experts for your trip");
resetCityPreferencesViews();
super.onStart();
}
public static void resetCityPreferencesViews() {
MakeATripStepFourFragment.deSelectFlyRadioButton.setChecked(true);
MakeATripStepFourFragment.selectFlyRadioButton.setChecked(false);
MakeATripStepFourFragment.deSelectAccommodationRadioButton.setChecked(true);
MakeATripStepFourFragment.selectAccommodationRadioButton.setChecked(false);
MakeATripStepFourFragment.deSelectActivityRadioButton.setChecked(true);
MakeATripStepFourFragment.selectActivityRadioButton.setChecked(false);
MakeATripStepFourFragment.viewModifyLayoutFlights.setVisibility(View.GONE);
MakeATripStepFourFragment.viewModifyLayoutHotels.setVisibility(View.GONE);
MakeATripStepFourFragment.viewModifyLayoutActivities.setVisibility(View.GONE);
}
for that city for those UI is not updating I use a LocalBroadcast call to Separate UI thread updating
if (!childFragment.onBackPressed()) {
// child Fragment was unable to handle the task
// It could happen when the child Fragment is last last leaf of a chain
// removing the child Fragment from stack
Log.d(MakeATripStepFourFragment.TAG , "this fragment.. "+childFragment.getClass().getSimpleName());
if(childFragment instanceof MakeATripStepFourFragment){
Log.d(MakeATripStepFourFragment.TAG ,"lets try it out");
if (cityManager.hasNextCity()) {
City currentCity = cityManager.getNextCity();
MakeATripFragmentFirstTime.destinationTextView.setText(currentCity.getCityName());
Log.d(MakeATripStepFourFragment.TAG, "updating radioButton with city.. "+currentCity.getCityName());
Intent intent = new Intent("update_radio-button");
intent.putExtra(MakeATripStepFourFragment.TAG,currentCity);
LocalBroadcastManager.getInstance(((MakeATripStepFourFragment) childFragment).getActivity()).sendBroadcast(intent);
}
}
childFragmentManager.popBackStackImmediate();
}
// either this Fragment or its child handled the task
// either way we are successful and done here
return true;
}
and in the broadcast receiver i call the updateViews() method
private BroadcastReceiver updatePreferences = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
City currentCity = (City) intent.getSerializableExtra(TAG);
Log.d(TAG , "recived call with city..."+currentCity.getCityName());
ExpertSelectorFragment.resetCityPreferencesViews();
updateViews(currentCity);
}
};
What maybe the solution I have to know . Please wanting perfect suggestion
Here on a button click looping through the city objects and adding fragment for them , if all city traversing completed then proceed to the next fragmet
case R.id.next_fragment_destination_button:
if (!cityManager.hasNextCity()) {
Log.d("status = ", "all city explored : " + cityManager.currentCityIndex);
cityManager.currentCityIndex = 0;
/*LocalBroadcastManager.getInstance(mActivity).unregisterReceiver(messageReceiver);
LocalBroadcastManager.getInstance(mActivity).unregisterReceiver(accomodationAllPreferenceReciver);
LocalBroadcastManager.getInstance(mActivity).unregisterReceiver(activitiesForCityPreferenceReciver);
LocalBroadcastManager.getInstance(mActivity).unregisterReceiver(updatePreferences);*/
setDataToGetExperts(cityManager.getAllCities().size());
} else {
Log.d("status = ", "going to next : " + cityManager.currentCityIndex);
Log.d(TAG, "current city size " + cityManager.getCurrentCity().toString());
cityManager.getNextCity();
//we have a next city
MakeATripStepFourFragment fragment = MakeATripStepFourFragment.newInstance(0);
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
// Store the Fragment in stack
transaction.addToBackStack(null);
transaction.replace(R.id.fragment_holder, fragment ,TAG);
transaction.commit();
}
break;
Update: Thank you all for attempting to help me solve this bug. I am still unsure as to the cause, I was able to roll back to a previous commit and continue development from there. This previous commit did show the same bug, however after I commented out button.performClick() it went away. Strangely, this does not work on the most recent commit.
I still do not understand this bug and would appreciate any more assistance in helping determine the root cause. My greatest fear would be to inadvertently re-introduce it.
I have the most crazy error I have ever seen.
The OnCreate method is being called over and over again, freezing my application and giving me a slight flicker. The only solution is then to exit to the home screen and force quit the application from the settings menu.
Here is what is happening in detail:
Application starts (Main Activity)
Main Activity calls the Second Activity
Second Activity calls onCreate, sets up as normal
Second Activity randomly decides to exit onCreate <-- I think this what's happening
Second Activity's onCreate gets called again. It doesn't ever return to the Main Activity.
I have run a debugger, it appears that the second activity successfully completes the onComplete/onResume sequence, then decides to exit and restart.
Has anybody ever heard of this behavior before?
I haven't noticed any exceptions being thrown. Also, in the course of debugging, I did go ahead and check those locations that you see as silent fail. (this is the older code before I littered it with print statements)
UPDATE: When attempting to stop the process, I must turn on airplane mode. This means it has something to do with this code block (Second Activity)
else if (Network.haveNetworkConnection(Login.getContext()) && Login.checkClientId())
{...}
With no internet, it will hit the else statement and does not display this behavior.
CODE:
onResume() of the Main Activity, where I call the Second Activity:
#Override
public void onResume()
{
super.onResume();
//Check If logged in, else go to login page
Login.setContext(getApplicationContext());
//Reset Notification Number
GCMIntentService.cancelNotifications();
/** GO TO LOGIN **/
if(!Login.isLoggedIn())
{
//If user is not logged in, open login page
System.out.println("RESUMING MAIN AND STARTING LOGIN INTENT");
Intent intent = new Intent(ActivityMain.this, ActivityLogin.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else
{
Login.setupStuffOnce();
Event.pullEvents(); //Get New Events
//Update ListView
updateMainFeed();
}
}
This is the Second Activity:
public class ActivityLogin extends Activity
{
private String postData;
//private Context c;
//final Timer timer = new Timer();
//Facebook Stuff
private Facebook facebook = new Facebook(Config.FBAPPID);
private AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
//Layout Stuff
EditText username, password;
Button loginButton, signupButton;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Open Database
Login.setContext(getApplicationContext());
Database.open(getApplicationContext());
}
/*
* #Override public void onPause() { s }
*/
#Override
public void onResume()
{
super.onResume();
// shouldn't put here but oh well
init();
//If coming from ActivitySignup
if(Transfer.username != null)
{
username.setText(Transfer.username);
password.setText(Transfer.password);
Transfer.password = null;
Transfer.username = null;
loginButton.performClick();
}
}
public void init()
{
Login.getUserLoggedIn();
if (Login.isLoggedIn())
{
//Do Any Additional Setup
Login.setupStuffOnce();
// If user is logged in, open main
Intent intent = new Intent(ActivityLogin.this, ActivityMain.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else if (Network.haveNetworkConnection(Login.getContext()) && Login.checkClientId())
{
// Else, Make User Login
// Inflate Login and Present Website
String clientid = Login.getClientId();
System.out.println("clientid:" + clientid);
//System.exit(0);
postData = "mobile=1&client_id="+Login.getClientId();
// Inflate the view
setContentView(R.layout.activitylogin3);
username = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
//Inflate the Button
loginButton = (Button) findViewById(R.id.loginButton);
signupButton = (Button) findViewById(R.id.signupButton);
signupButton.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent = new Intent(ActivityLogin.this, ActivitySignup.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
}
});
loginButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
int res = Login.sendLogin(username.getText().toString(), password.getText().toString());
if(res == 202)
{
//Login Successful
//Check if facebooked.
if(Login.isFacebooked())
{
//Just go to main
Intent intent = new Intent(ActivityLogin.this, ActivityMain.class);
//Are these flags necessary?
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else
{
//Go to facebook login page
//Intent intent = new Intent(ActivityLogin.this, ActivityFBLogin.class);
//startActivity(intent);
//Login via Facebook
doFacebook();
}
} else
{
System.out.println("Login Failed: "+res);
if(res == 405)
{
Toast.makeText(getApplicationContext(), "Incorrect Username/Password", Toast.LENGTH_SHORT).show();
password.setText("");
}
else
Toast.makeText(getApplicationContext(), "Network Error", Toast.LENGTH_SHORT).show(); //Not entirely true in all cases i think
}
/*Login.getUserLoggedIn();
if(Login.isLoggedIn())
{
Intent intent = new Intent(ActivityLogin.this, ActivityMain.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(), "Please Login Above", Toast.LENGTH_SHORT).show();
}*/
}
});
} else
{
// Not Logged In and No Internet Access
setContentView(R.layout.activitylogintext);
EditText text = (EditText) findViewById(R.id.text);
text.setText("No Internet Connection Detected\n requires internet to login");
Button button = (Button) findViewById(R.id.refreshButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//Login.getUserLoggedIn();
if(Network.haveNetworkConnection(Login.getContext()))
{
Intent intent = new Intent(ActivityLogin.this, ActivityLogin.class);
//intent.setFlags();
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(), "No Internet Access Detected", Toast.LENGTH_SHORT).show();
}
}
});
}
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
public void doFacebook()
{
facebook.authorize(this, Config.facebookPermissions, new DialogListener() {
#Override
public void onComplete(Bundle values) {
/*SharedPreferences.Editor editor = state.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
*/
//Input into database
Login.saveAccessToken(facebook.getAccessToken());
Login.setFB(facebook.getAccessToken());
//Login.sendAccessToken(facebook.getAccessToken());
//Intent into Main Activity
Intent intent = new Intent(ActivityLogin.this, ActivityMain.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
#Override
public void onFacebookError(FacebookError error) {
Toast.makeText(getApplicationContext(), "Error: "+error.getErrorType(), Toast.LENGTH_SHORT).show();
}
#Override
public void onError(DialogError e) {
Toast.makeText(getApplicationContext(), "Error: "+e.getMessage(), Toast.LENGTH_SHORT).show();
}
#Override
public void onCancel() {}
});
}
public boolean checkForUserID(Context c)
{
try{
String res = Network.getUrl("www.website.com/mobile.php?got_user=1&client_id="+Login.getClientId());
JSONObject json = JSON.constructObject(res);
if(JSON.handleCode(json))
{
if(json.getString("type").equals("userid"))
{
Login.setLogin(json.getString("data"));
return true;
}
}
} catch(Exception e)
{
//Silent Fail
}
return false;
}
}
I believe that the problem will be resolved if you finish your MainActivity after you call SecondActivity. The problem probably is that the onResume event is immediatelly fired when you resume your MainActivity. That is because the MainActivity was probably destroyed and recreated while it was in background. Another solution would be to save your Activity's state with onSaveInstanceState. See here for more information.
Check this code in your activity:
Button button = (Button) findViewById(R.id.refreshButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if(Network.haveNetworkConnection(Login.getContext()))
{
Intent intent = new Intent(ActivityLogin.this, ActivityLogin.class);
//intent.setFlags();
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(), "No Internet Access Detected", Toast.LENGTH_SHORT).show();
}
}
});
Here you are calling ActivityLogin itself.
That's why the onCreate() is being called again and again.
I had a similar problem once. The problem occurred because I made configuration changes without declaring them in the android:configChanges attribute of the <activity> tag (and hence it recreates itself the whole time).
For example, if you change the locale manually you need to add locale to android:configChanges!
It seems to me there is a good chance for endless cycling here if Login is not properly shared between the activities, causing Login.isLoggedIn() to return true in ActivityLogin but false in ActivityMain.
A few critical factors are where your Login object is located, is it static, how is it referenced between Activities? It is entirely possible that ActivityMain is being destroyed while ActivityLogin is active; storing the Login data in SharedPreferences or a database, or otherwise persisting it is important. How does isLoggedIn() resolve (determine its return value?)
Suggestion 1: Consider making use of the Singleton pattern (if you haven't already.)
Suggestion 2: While discouraged, you could store Login at the Application level.
Suggestion 3: You can try using Intent.FLAG_ACTIVITY_SINGLE_TOP to reduce the likelyhood of a new ActivityMain being created - which might not have access to Login, again depending on how you have it stored.
ActivityMain
onResume() {
if(!Login.isLoggedIn()) {
/* Not logged in, launch ActivityLogin! */
Intent intent = new Intent(ActivityMain.this, ActivityLogin.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
ActivityLogin
onResume() { /* ... */ init(); }
init() {
Login.getUserLoggedIn();
if (Login.isLoggedIn()) {
/* Internet - launch ActivityMain! */
Intent intent = new Intent(ActivityLogin.this, ActivityMain.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // <--- suggested addition
startActivity(intent);
else if (Network.haveNetworkConnection(Login.getContext()) && Login.checkClientId()) {
/* No internet, the user was unable to login. */
}
I think your main problem is with you onResume function as it gets called each time it comes back into view (eg: you start second activity, finish it, main activity onResume is called again. If you finish your second activity (or it quietly crashes for some reason) you will go back to your mainActivity and call onResume (which will start the cycle all over again).
Now i dont know if you are finishing activity 2 somehow but I would check that.
EDIT:
ALso I would put some logcats here
if (Login.isLoggedIn())
{
//Do Any Additional Setup
Login.setupStuffOnce();
// If user is logged in, open main
Intent intent = new Intent(ActivityLogin.this, ActivityMain.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
Log.i("Some Tag", "Starting Main Activity From Activity 2");
startActivity(intent);
}
The above adding of the log.i will allow you to know if this is where the error happens, and you can go from there.
I had similar problem where the activity would be recreated all the time. Re-installing the app wouldn't help, but restarting the phone did the job.
I've run into this error before, but thought it was some mistake by the strict mode system. However, it apparently was right as I sadly found out now. :(
My programm is made of one Activity and loads of Fragments. I have a NetworkWorker fragment, which starts URL requests like this:
public void startURLRequest(Fragment target, String url, String message)
{
if (asyncTask != null) asyncTask.cancel(true);
asyncTask = new FragmentHttpHelper(url, message, target);
asyncTask.doInBackground();
return;
}
FragmentHttpHelper is a custom inner class derived from AsyncTask:
private class FragmentHttpHelper extends AsyncTask<Void, Void, String>
{
//...
#Override
protected String doInBackground(Void... params)
{
if (CheckInternet())
{
try
{
URL myURL = new URL(url);
httpClient = new DefaultHttpClient();
if (this.message == null)
{
httpRequest = new HttpGet(myURL.toExternalForm());
}
else
{
httpRequest = new HttpPost(myURL.toExternalForm());
HttpEntity myEntity = new StringEntity(message, "UTF-8");
((HttpPost) httpRequest).setEntity(myEntity);
}
// and so on...
}
//catches
finally
{
// auf jeden Fall Verbindung beenden
if (httpRequest != null) httpRequest.abort();
// if (httpClient != null) httpClient.close();
}
}
else
{
showDialog(getString(R.string.net_notify_no_network), target);
}
//...
}
/**
* gets called after AsyncTask has finished
*/
protected void onPostExecute(String result)
{
if (target == null)
{
((NetworkWorkerListener) getActivity()).onDownloadHasFinished((!result.contentEquals(ERROR)), result);
}
else
{
((NetworkWorkerListener) target).onDownloadHasFinished((!result.contentEquals(ERROR)), result);
}
}
}
NetworkWorkerListener is just an interface for a callback on the Fragment which started the URL request. This class has always worked fine when I used it in my 2.2 app. I would derive it in my Activities then.
Now, if a menu item is selected, another worker Fragment starts the URL request via the above method and opens a loading dialog:
FragmentManager fragmentManager = getFragmentManager();
NetworkWorker network = (NetworkWorker) fragmentManager.findFragmentByTag(TabletMain.NETWORK);
if (network == null) return WorkerFeedback.NO_NETWORK_WORKER;
myDialog = LoadingDialog.createInstance(getString(R.string.notify_download), this);
myDialog.show(fragmentManager, TabletMain.ONETIME);
network.startURLRequest(this, someurl, null);
At least that's what supposed to happen.
Instead, when I click the menu item, my app freezes and no loading dialog is shown until. Next happening is the reaction to the end of the download (or, in my case an error message, as I am sending nonsense strings). Meaning onPostExecute() was reached.
I feel really stuck now - is it not possible to use AsyncTask with Fragments? Or did I do something wrong?
Thanks for your help,
jellyfish
Don't call doInBackground directly, call execute instead (on the async task)