android complete action dialog callback - android

I've such situation:
By clicking on button from activity we should open browser, and finish activity.
But, if the user has more then one browser Complete Action Using dialog is showing, so user can complete action by choice or return to application by pressing back.
I should finish activity only in case that browser opened.
Is there any way do determine that intent delivered succefully?
Is there any to determine if Complete Action Dialog has been cancelled by pressing back?
If none of above, any suggestions reagards solving this problem?

Related

How to tell when user selects "Open in Chrome" from menu

I'm trying to determine when the user opens a Chrome Custom Tab in Chrome (the "Open in Chrome" option from the menu).
My navigation callback returns an event code of 6, which is the same code returned when the user closes a Custom Tab. Is there a way to differentiate between whether the user has closed the Custom Tab or opened it in Chrome?
Navigation code 6 means that CustomTabs Activity is not visible any more for either user has navigated back to the activity that started the CustomTabs intent or another activity, in this case Chrome has been started, has taken place.
When the user navigates from CustomTabs activity to Chrome you get navigation code 6, when back button is hit, another event is sent with code 5 (tab visible again). In this case you are the CustomActivity is still visible, previous activity was finished, the activity that started the intent is still paused.
Starting CustomTabs for activity might solve your case when you have navigation code 6 and onActivityResult() method called on the activity that started the session.
public void openUrlForResult(String url, int requestCode){
CustomTabsIntent customTabsIntent = buildCustomTabIntent(mCustomTabSession);
customTabsIntent.intent.setData(Uri.parse(url));
mContext.startActivityForResult(customTabsIntent.intent, requestCode);
}

Is it possible in android to leave an AlertDialog in front of changing Activities?

I have an app with multiple Activity classes. In one part, one is a main screen and the next is a login. The user would open the login screen and enter their info and press a button to submit it. The resulting code opens up an AlertDialog to tell them the registration status, along with some other information. If the registration itself was successful, they will return to the previous activity. But this makes any AlertDialog disappear with it.
I want the background to return to the previous activity so they can see the home page start updating, but I want them to see the alert message long enough to read it.
Yes this is possble. By using a service you can display an alertbox which runs in foreground for a long time. I have done thissame kind of thing for a news app.
It will run in foreground for a long time and when you want to switch you can stop the service than it will dismiss the alert box-.
In my case I displayed a custom view with buttons in the foreground.

How to show alert Dialog when home button is pressed ?(ICS)

I want to show alert when user presses home button on device(do you want to exit the app ?)
How to do it ?
You can't handle Home button click, because of Android policy (Home button click event handling android). Of course, you can use onPause()/onStop() method of your current Activity, but your application will be moved to background too quick and user will not see your dialog, I think.
Also, note that Home not closes the app - just moves to background. User usually close app by pressing Back on main activity, try to handle it:
#Override
public void onBackPressed() {
// your dialog here
}
Is is not possible for Android apps to override the functionality of the home button. The best you can do is show the dialog when the user presses back in your topmost Activity.
You can find more information at the following SO answers:
https://stackoverflow.com/a/7240268/3214339
Android Overriding home key
Write the show alert dialog code in onPause() it will work perfectly.

Activity not closing properly

I am calling one activity on click of status bar notification which is having a Complete button. on click of btn. i have folllowing code -
public void completeTask(){
taskDBAdapter.deleteReminder(rowId);
taskDBAdapter.close();
Intent intent = new Intent(this, TaskManagerActivity.class);
startActivity(intent);
finish();
}
whhen i click complete btn new activity (TaskManagerActivity) gets opened properly.But if i reopen my application it still tries to open this activity and not my default landing activity. Any help on this.??
EDIT -
I have tried repositioning my finish() statement . Still its not working.
EDIT 1.1 -
Ok I will provide some details here. Assume my app has two activities
Main Activity
Notification Activity
My app create some notification to display on Status bar. So as soon as i click on status bar Notification actvty will open. Now there is a button called Complete on click of which the code given will fire and main activity (in the code TaskManagerActivity.class) will open. But after I press back button in my app and again reopen it , it opens the notification activity when it should have fired the main activity (as it is launching activity).
Thanks,
Ray
That's the default way android functions. If you press the home button and then open your app again, it will restore the apps previous state (unless it has killed the apps processes and activities due to memory constraints). So you are not actually restarting your app but only restoring it.
If you wanna quit the app, then press the back button. Now when you re-open the app, the original activity will be launched.
Do not modify this behavior. It is the default system behavior and users expect it to work this way. Your app is fine :-)
- First of all the behavior which you are experiencing is the way Android is made to function, moreover when a user gets a call while this app is open, after finishing the app he will definitely want to get back to the state where he left the application.
Still if you want it that way, here it is.....
- Make sure your application has only single instance of it running, by using android:launchMode="singleTask", or android:launchMode="singleInstance"
- Then finish() your Activity at onPause().
#Override
void onPause()
{
super.onPause();
finish();
}

How to handle feedback from background threads if the user uses the back button?

I have the following problem:
I have an Activity where a user can start a web search showing a new activity to show a progress bar until the results are shown. Now the user can either wait for the results or maybe think about the search parameters, hit the back button and triggering a new search. The search is running in an Async Task and therefor still running if the user hits back.
At the moment the thread finishes it calls some methods on the old activity causing the activity to show a dialog.
This causes the system to crash because the dialog tries to show itself with a reference to an activity that is not longer present on the screen.
How can I achieve a dialog that is only shown if the activity is still active?
Call isFinishing() on your activity.

Categories

Resources