picture which is shown while one activity starts after another - android

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.

Related

Too many Activity in the stack make the app pretty slow

Recently I created a social app. I didn't use fragment and the project is almost finished. I have several Activities like UserProfile, Followers, Followings activity.
Normally it's just working fine. But if user click UserA UserProfile activity -> and then click A's Followers -> select UserB Userprofile activity -> click B's followers activity -> select UserC Userprofile activity....
In this loop, the app would get pretty slower because it opened too many activities at same time and the back stack hold all of them.
I just wonder if there's any optimization I could do for this situation? Because UserProfile activity layout would always same except the user information content. Is that possible to use Fragment for each activity, even though different activities would show up in sequence one by one?
Thanks!
You should architect this in a different way. You should only ever have one UserProfileActivity in the stack. If you already have the UserProfileActivity for User A in the stack, and you want to show the UserProfileActivity for User B, just call startActivity() for UserProfileActivity with Intent.FLAG_ACTIVITY_REORDER_TO_FRONT and pass some extras to indicate that the Activity should show User B. Use the same concept for all of your activities.
To make sure that the BACK button navigation works correctly, you will need to override onBackPressed() and figure out what Activity needs to be shown and with what data. Then call startActivity() and also set Intent.FLAG_ACTIVITY_REORDER_TO_FRONT and provide extras so the Activity will show the correct data.
To assist in keeping track of where you are in the navigation, you might want to create a stack of items that are stored in a static variable somewhere. Each item would indicate what Activity is being shown and with what data. Every time you launch a new Activity, you push a new item on to this stack, and every time the user presses the BACK key, you pop the top item off the stack and then look at the one underneath it to determine what Activity to start and what data to send in the extras.
With this scheme, the user can click around all day long and you will never have more than one instance of each Activity, but the user will still be able to navigate all the way back.

Android tasks and backstacks

I am trying to do something very simple, but yet it seems that its very complicated in Android
I have to support the following use cases
Launch app from launcher
Launch app from notifications
Assuming I have 3 activities (splash, main, details) and 2 notifications
one tied each to main and details
Activity Notification
Splash
Main NotifMain
Details NotifDetails
which show up in the notification shade I end up with the following scenarios
Launch app from launcher
Splash -> main
App is in foreground showing Main and user taps on NotifMain
I see a second instance of main is launched even though main is configured as singleTask
App is in background and user taps on NotifMain
Works as expected, and there is only one instance of Main
User is on Main, but taps on NotifDetails
This causes NotifDetails to show, now, since in navigation because Details should take user back to Main, if I do that, I see Main twice
User is on Details, and taps on NotifMain
I see Main, on which if I hit back it takes the user back to Details, on which if I hit back takes the user back to Main again.
This is very confusing and complicated. Is there a simple way to handle this scenario..
All i wish to do is.. that irrespective of my paths
if the usr taps on NotifMain, then there is only Main running for the application, with all other tasks cleared.
If the user taps of NotifDetail, then you have Main -> details in the application.

Android app - delete item from list following an action in another activity

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

Maintain Single instance of an activity

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.

Opening an activity that instantly calls another activity: I don't want the first one to be seen

I have an application with a Main Menu to access several options. One of these options is the main option (List Tasks). This application has a log in system that works with accounts.
I want to have something like WhatsApp. In WhatsApp, when you click on a notification the conversation is shown, and when you close that conversation the activity with all your conversations is shown. I want that, when you open the application, the List Tasks activity is shown, and when you close this one you'll see the Main Menu. To do that I made MainMenuActivity to call TaskListActivity as soon as it's created.
This works fine when I open the application and I'm logged in, the user doesn't see that two activities are opened, it seems like TaskListActivity is the only one opened. But if I do it when I log in (from AccountAuthenticatorActivity), the MainMenuActivity is shown for half a sec and then the TaskListActivity is shown.
How can I fix it? I'm doing it the wrong way?
Do what you need to do in onCreate() (but do not call setContentView() - it'd be pointless), fire new intent to call another activity and then call finish() to kill your "transitional" activity at the end of its onCreate(); Voila ;)

Categories

Resources