showing some view in all activities without duplication of code in Android - android

I have a condition when a specific event will occur in background, I have to show a Floating Action Button in bottom of activity to notify the user if App in fore ground. No matter in what activity the user is, if that event trigger by a service, I have to show a FAB not a dialog, I mean user can interact with activity and FAB both at the same time. How could I achieve this if I do not wanna repeat the same code in all activities of my app.

You can make a utill class and make a static method in that class so in which activity you want to access that method just Classname.methodname and send parameter.
or you can use that method in that Activity and extend from that activity

You can create a simple activity that matches your need and make all other activities derived (inherited) from that one.

Related

Launching a dialog from a widget does not work properly

I have a widget that launches a dialog with two options. One Button to make emergency call, and another to call customer service. Once the dialog is launched from a widget, and I tap on one of the two option, the button doesn't respond. But, if I background the app and bring it to foreground, then that previous selection of the button that I made gets called. I'm using the correct flag when launching the activity from the Widget.
The order of the lifecycle of the Fragment that takes place when things are working normally with the Dialog is below. The similar lifecycle takes place when foreground and backgrounding the app. Not exactly sure why the callback for the buttons on the Dialog doesn't respond when launched from the Widget. Thank you!
OnCreateView()
OnViewCreated()
OnStart()
OnResume()
I was able to fix this problem by simply using navController.navigate(). This allows the NavController to handle the Fragment lifecycle properly and in the correct order.

how did facebook messenger switch between activities

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/

How to access KeyChain.choosePrivateKeyAlias activity?

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.

how to access button/view of an activity from another activity

I have a button in an Activity and when on clicking this button, some operation will be performed in another activity. And I should call the buttonclick event in 2nd activity only.Simple saying, I have a TabActivity with button and upon clicking the button some operation should be performed in the underlying tabs. ButtonClick event should be in the tab.
How can I achieve this?
create one common function in a helper class and call it from both the places.
You could broadcast an Intent from your first activity to be received by your second activity. When your button is clicked, it's parent activity broadcasts a unique intent which your android manifest will route to your second activity for receiving.
There is a good example of that here:
http://thinkandroid.wordpress.com/2010/02/02/custom-intents-and-broadcasting-with-receivers/
However, have a look at the android reference and consider using a LocalBroadcastManager which is more appropriate if you are just broadcasting within your process.

Activity launches transparent Overlay Activity. How to pass Data without closing the Overlay?

in my app i am having an Activity that launches another Activity ontop of it. The second Activity is meant to provide controls like next and previous for the first activity.
How can i pass button events between the two activities that are visible at the same time without closing the Activity with the controls?
You can send Broadcast in order to communicate between Activities.
In parent Activity register BroadcastReceiver, then send a Broadcast by calling sendBroadcast(..) in child Activity.
It sounds like what you are trying to do doesn't require two activies, but rather additional view objects on the main activity that will be shown/hidden/removed/added as buttons on this activity are pressed.
If you need additional help, I would recommend elaborating on your original post.

Categories

Resources