I have two activities Activity A and B, Activity A has 3 fragments namely a1,a2 and a3. a3 is the default selected fragment which shows videos, a2 contains one big textView and a small edittext in it and a1 contains a listview.
Now On activity A's title bar I have a button, and since it is on title bar it is visible from all 3 fragments. OnClick of this button I open Activity B. using Following function.
public void inviteUser() {
if ( getUserType() == ACTIVE ) {
Intent intent = new Intent(this, B.class);
intent.putExtra(Constants.MEETING_ID, (long) session.getSessionId());
intent.putExtra(Constants.INVITE_FROM_SESSION, true);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_SINGLE_TOP);
this.startActivityForResult(intent, RESULT_OK);
} else {
Toast.makeText(this, getString(R.string.strNotAPresenterMsg), Toast.LENGTH_LONG).show();
}
}
Inside B I call its setResult(ResultCode) and finish()
. Now I have two problems when I start B from Fragments a1 and a2,
1. B takes too much time before returning back to A (i.e. after pressing back button or after finishing the work of B), 2. It doesn't show any dialog after returning until either I navigate to some other fragment or I rotate the device, once I do that it starts behaving normally and surprisingly,
when I start the activity B from fragment a3, it returns immediately and behaves normally.
I have tried overriding all the life cycle methods of these fragments and put the Log statements inside each method. Pain is that method calling sequence is normal and same for both the cases.
I have tried changing the flags of the intent but to no gain.
I have added falg android:configChanges="keyboardHidden|orientation"
for all the activities of my app.
Hope I explained the problem, in case any one need any specific part of the code. please comment.I will edit the question and add that. Help guys!!!
EDIT I was testing in GingerBread 2.3.6 it was not working but I just checked that on emulator running JellyBean and it is working fine. Looks like the issue is related to OS version. Any idea ?
EDIT 2 One important point of observation is that When in B I press back button, after few mili seconds the onResume() of Previous Activity and their fragments are called. But even after that B is on Screen for some time and that seems like phone hanged for few seconds....
EDIT 3 Just got to know that onStop() and OnDestroy() of B are not called when I start the B from Fragment a1 or a2. However They are called perfectly when I am on a3. What could be the reason for this ?
The doc says that "The visible lifetime of an activity happens between a call to onStart() until a corresponding call to onStop(). During this time the user can see the activity on-screen, though it may not be in the foreground and interacting with the user."
Since onStop() is not guaranteed the activity behaves abnormally when it is not called.. I also came to know that in HoneyComb+ devices it is always called. I have tried calling onStop() inside onPause() but that is not working. What I do now ?