i have button in my first activity called Start.
Now when i click on this button it takes 1 to 2 seconds to load the next activity, now at that time the user clicks on the start button multiple times so what happens is that the next activity will open multiple times.
How to overcome this? Is there any way that even if the user clicks on the Start button multiple times open the activity only once.
Your Options:
On click, disable the button and display a ProgressDialog to the user.
Use the Intent flag FLAG_ACTIVITY_SINGLE_TOP to ensure only one activity is maintained on the stack. Documentation
Use the qualifer launchMode=singleInstance in your AndroidManifest.xml so only one instance of your Activity is allowed at a time. Documentation
I would recommend the first, because it can show the user your application is still working even if it takes a few seconds to do the necessary processing to begin your Activity.
You can put the launch mode of your 2nd activity as "Single Instance" in your manifest file.
Don't use anything like a launchMode or Intent flags. They are used for different purposes.
Description here
What you have to do is:
Show a progress dialog to clearly show the user that an
action(calling 2nd Activity) is in progress. This was user will not
try to click the button multiple times
Simply disable the button's click listener after 1st click. This is not
recommended because user might not be able to know whether he/she
clicked the button. Also this is the case where user tends to click
the button multiple times.
Related
I want to show the same image on the screen non-stop while the 3 activities start one by one : LoadingActivity, MainActivity, and then DetailActivity, and all this time the user sees only one image.
Thus, the picture should hide starting multiple activities in a row. Typically, when the application starts, starting LoadingActivity, then MainActivity, then DetailActivity. Usually it ends at the MainActivity, and while the LoadingActivity is starting , the user sees the Welcomу layout for a few seconds, and then the MainActivity interface. It's very rarely necessary to go to the DetailActivity, for example, when the browser link to the DetailActivity has already been chosen.
But when I get a push notification, I need to go to the DetailActivity immediately bypassing the LoadingActivity and MainActivity, I do not launch multiple services, do not take updates from the server, do not set the required variables, which means that when the user tries to do something from the DetailActivity, the functionality will be limited.
But what I'm trying to say is that I don't like that all 3 interfaces are shown when user presses the push notification, so I decided to ask if it's possible to have only one picture hanging during all these three activities loading?
To get a picture hanging in a row, all three activities, I duplicated to the MainActivity some key points from the LoadingActivity. Push starts MainActivity, if it is push, then I don't show a main layout, but an additional, with a picture. Next, I run websoket, login and query the server for updating data relating to this particular push. I receive data and load the DetailActivity, displaying the right information.
Additionally I made: - in onStop of MainActivity I switch to main layout, so that when user press the back of the DetailActivity, he sees a normal layout of the MainActivity.
- If within 10 seconds do not get a response from the server, then just display DetailActivity without new information. This is not good, but better than to open the MainActivity user may not immediately find the desired option and opens DetailActivity.
The following method:KeyChain.choosePrivateKeyAlias creates system dialog which allows user to choose a key alias from a list. As one of the arguments it takes Activity context which will be used to spawn this dialog. When selection is made it will call a callback.
In my scenario user doesn't select any alias but presses "Home" button. I would like to intercept this event. How can I do that?
Also I would like to cancel this dialog programatically. In this case I need some way to access this child Activity (please note that choosePrivateKeyAlias doesn't return any "handle" to the new dialog). Is it possible to access child Activity without any references (handle/id/etc.) to it?
There is no way to programatically end that activity because it is a system activity. It's the same as launching the browser on your device or the contact list. The only way to exit it is to press back and it will close that activity and resume yours.
According to my understanding, if you want to dismiss that dialog. Then as far as I know about Android OS. There are lifecycle methods for Activity. So I think
IF YOU CALL "yourDailog.dismiss()" INSIDE YOUR ACTIVITY's "onStop()". SO YOUR PROBLEM WILL BE SOLVED
If you do it in above way, so whenever you press HOME button, It will call onStop method of your activity. At that time, It will dismiss that dialog.
I'm creating an app where I display a list of pending challenges. When the user clicks on a challenge, he can accept it or ignore it.
Here's what I want to do and I don't know how :
if the user accepts or ignore the challenge, call this.finished and remove the challenge from the list
if the back button is pressed, do nothing, the challenge is still visible
In short, if the user really responds to the challenge I don't want it to be displayed in the list, but if he doesn't choose any option and press the back button, he didn't choses one of the two actions so I want that challenge to still be visible in the list.
I don't think it's possible to detect what button I've pressed when i go back to my main activity. I've thought about using global variables, but I don't want to misuse them either.
Just to be clear, I'm not asking how deleting a list item. But when to know deleting one depending of the actions of another activity.
Give your second activity the index you want to remove as a parameter inside the intent and let it finish by returning the index again as an intent extra (by using setresult(Intent i) and then calling finish) inside your first activity catch the result from your second activity by overwriting onActivityResult (http://developer.android.com/reference/android/app/Activity.html#onActivityResult(int, int, android.content.Intent))
see 3.3. Retrieving result data from a sub-activity in http://www.vogella.com/tutorials/AndroidIntent/article.html for a detailed howTo
Here i have a few activities that consist different menus in my app..
The problem is that i want to add a are you sure popup box to exit the current menu and return back but calling finish() method on the click event of yes button of popup box causes all activities to terminate and app exits...
I want to make a way to terminate only the foreground activity and
return to last activity programatically (i.e without using back key)
Can u post some source code regarding how you start you new activities? Are you starting multiple activities at all? finish() method only finishes the current activity and not the entire stack of activities, thus the system automatically brings to front the previous activity from the stack. I can't understand your question please provide some further details.
I am building an application that has 2 classes
- Buttons_Class
- Display_Class
I want to keep them as separate classes.
When the user clicks on a button the OnClick routine in the Buttons_Class creates an intent and a bundle and starts the Display_Class activity. This is working fine. The Display_Class gets the information and displays it in a TextView.
What needs to happen next? If the user clicks on a second button, does the Display_Activity need to be recreated? Does a new intend need to be created? How does the information go from one activity to the next every time the user clicks on a button.
Any examples will be greatly appreciated.
If the user clicks on a second button, does the Display_Activity need to be recreated?
When you call startActivity(), by default, it creates a new instance of the activity. You can control that with flags on the Intent if you want, such as FLAG_ACTIVITY_REORDER_TO_FRONT.
Does a new intend need to be created?
If you are starting a different activity, yes. If you are starting another copy of Display_Activity, perhaps not.