how did facebook messenger switch between activities - android

how can facebook hide current activity and show another activity here in chathead
when choose another one to talk with him its hide current popup floating activity and show the other one activity
i don't think its start new activity because i write some message on current activity in the editText without send it and when choose another one to talk with him its hide current activity and when i back open it the text i write it it's still there thats mean it's dosen't start new activity when switch to other conversation
iam try to make something like facebook chathead but i have problem i switch between floating activities

They are using Fragments and Floating Action Buttons.
Also just for your information, unless you specifically call finish() on an activity, it will only get stopped when the new activity is started. When you return, it will go back to onResume() state.
Please look into activity life cycle and Fragment Life cycle to know about these things more clearly. The faster you have a clear idea about these, the easier it will be in the long run
https://developer.android.com/training/basics/activity-lifecycle/index.html
https://developer.android.com/guide/components/fragments.html
NOTE: When it is on the home screen, It is an window running on top of the background service with a floating window , while inside the app it is a Fragment.
see tutorial: http://androidsrc.net/facebook-chat-like-floating-chat-heads/

Related

How should I manage the activity stack?

I have an app with a main menu at bottom; I can't figure out how should I manage the activity stack, because every button opens an activity, and each activity can start more activities, and i was looking for a management in the style of the current Instagram's app. It looks like (in the Instagram app) that every activity started by each button in the bottom menu opens a new activity stack, but when you press back button, it navigates in the reverse order you called every activity.
Sorry for my bad explanation, i hope that you can understand my aim.
You could check out Instagram Android app to figure out what is my goal.
My current implementation uses a MainActivity with a Fragment for the first menu button (Qui in giro->"Nearby"), but i probably should change this approach.
Thanks.
1) Firstly you will have to decide what will be your main activity.
2) Now use this main activity like as star topology. Means this main activity will be center activity.
3) Use to finish() method for finish back stack before receiving at this center activity.
4) After it if you open another side of your main activity than you will see only new back stack will be displayed after pressing back button for receiving at main activity again.

Could someone please explain FLAG_ACTIVITY_PREVIOUS_IS_TOP

I have an Android app with multiple activities. The main activity communicates over a network and can launch or dismiss various other activities depending on commands it receives over the network. When an Activity is dismissed I don't want to finish() it, just move it down the stack so it's no longer the top activity. What I really need is a FLAG_ACTIVITY_REORDER_TO_BOTTOM but there is no such thing.
There's an intent flag called FLAG_ACTIVITY_PREVIOUS_IS_TOP and the name implies something like that but I don't understand the description:
"If set and this intent is being used to launch a new activity from an
existing one, the current activity will not be counted as the top
activity for deciding whether the new intent should be delivered to
the top instead of starting a new one. The previous activity will be
used as the top, with the assumption being that the current activity
will finish itself immediately"
Could someone please decode that for me, and if it's not what I want IS there some way to tell an activity to submerge itself below the previous one?
This isn't possible. The activities are stacked and you cant put one back under the other. It sounds like you may want to create a class that extends Android’s android.app.Application.
I found this tutorial online and it looks good. Good luck.
Extending Android's android.app.Application tutorial
You cannot move an activity below a certain activity into the android back Stack. The only way to move a activity in back stack is to open another activity on top of it. You can move an activity on top by creating a single instance of activity using FLAG 'singleTop' in this way your activity will be moved to the top of another activity and only a single instance of activity will be there in stack.
More information about activity back stack and Flags is available here.
Go through this information and all your doubts will get cleared about back stack.

how do i close a specefic activity and get to previous activity Programatically?

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.

android - How to Exit from the application

My Application have 20 activities. Here i want to implement the how to exit from the application when you click on the button(like Logout). it means if you click on the menu button any where of our application then it shows the one button. if click on that then directly comes out from the application. how to implement it.
thanks
Well naresh you can do something like that
first finish the activity from which you are closing application this.finish(); secondly and most impotantly always set a flag i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
this clear top when you switch from one activity to another activity and as you know every activity is kept in stack to so this flag remove old activity from top and push new activity in top so around your whole application only one activity is kept in stack
and if this does not work put the whole application in background by avtivityname.moveTaskToBack(); this will move your whole app in back ground but only one drawback when you start your activity it will show your that activity from which you have moved back
System.exit(0);
should work, don't forget Java common functions work on android, there isn't only the android library!
As for the button being in the menu in every activity, you could create a class derived from Activity which creates and handles the menu properly, and make every other activity inherit that derived activity.
First finish the activity from which you are closing application: this.finish();. Secondly and most impotantly always set a flag i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); This clears top when you switch from one activity to another activity. As you know every activity is kept in a stack to so this flag removes old activity from the top and pushes new activity to the top so around your whole application only one activity is kept in the stack.
If this does not work, put the whole application in background with avtivityname.moveTaskToBack();. This will move your whole app to the background. One drawback: when you start your activity it will show your that activity from which you have moved back.

Android: Recovery Activity When I press Home

i have the following question.
I have an activity which is showing a progress bar while a service is downloading data from an API.
I want that when i press Home and relaunch my program the activity and which is not the first activity called but it is in the stack was recovered in order to continue showing the progress.
I have read about the cycle of life of activities but i don't find a clear solution.
The same thing happens If i am in the activity which is showing the progress bar and i press a button that takes me to another activity, when i go back, can i recover the old activity instead launch one new?
Anyone helps me?
Thanks
The problem is that pressing the home button will erase the whole activity stack. That means there is no possibility to go back to the activity it even is not certain that the activity still exists.
If this a progress that is interesting for the user that it is still running you could display a notification bar icon until the progress is finished. I think you can specify a special intent for clicking on the notification bar and filter this intent with your activity. That way you would go back to the activity. But you still face the problem that the activity is saved and has no reference to the background thread doing the work.
If your Activity has left the stack its finish method is called. You shouldn't try to reuse this activity later on. The best way is to think of a way that the whole state of the activity can be saved and restored later on. To restore a reference to the background thread doing the work you could subclass the application class and save a reference to the running task in your subclass.

Categories

Resources