I want to call the click event of specific button of other activity from my new activity. Is it a possible in android and if yes then how can I achieve the same.
You could implement and interface in the one activity and call it in the second activity.
Related
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.
I have an activity which has a button which opens up a custom AlertDialog (in which user can enter some data) when pressed. I now have a requirement to open this activity with the alert dialog open initially.
I know that I can perform a click on the button programmatically by calling button.performClick();. My question is, when should I call this? Is it safe to call it in onCreate()?
Yes , you can call it in onCreate() , if you want to call it only once,
but if want call that again you leave and come back to Activity it will be better to add in onResume().
Yes, you can call it in onCreate(), but if you set the AlertDialog as a login, I think it will be in onStart(). Because when you go to desktop, then if you want to get back, you should login again, right? And you can read the detailed information in this.
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.
When I click back button in my app I want to change some data in previous activity.
public void onBackPressed() {
super.onBackPressed();
Log.v("Back Button ","Pressed");
}
I am trying to using this but cant help it out ?
do I need to maintain backstack of activities which back button internally does?pls help
i want to change menubar images (wriiten by me bottom of every activty in my app) item which is present in every activty but when I click menubar (clickable) it is not able to change menubar images as per activity changes.
You want to look at startActivityForResult. The previous parent Activity should spawn the next one with this call. Data can be passed backwards via extras (Bundle) in an Intent when returning to the parent Activity in onActivityResult - or you can simply use the result codes.
You can find more information here: http://developer.android.com/reference/android/app/Activity.html#StartingActivities
Better use with onKeyDown. & onKeyDown Example
Just override this android's default method. It'll provide the changes with whatever you want.
I am totally new to android development....what piece of code shall I write to move back to the last activity from the current activity on a button click?
I use intents to switch between the activities but is there anything specific to resume back on the last activity?
Please advise...
Thanks,
Pressing the back button should do that "out of the box"...
If the user clicks on Back button, application will automatically take you to previous Activity. You don't need to do anything.
If what you pretend is to implement that action from current Activity, for example through a Back menu option, just call finish() in your Activity. You can call setResult before that, if you called that activity with startActivityForResult
Ger
By default back resume previous activity.
You should read this to better understand android Activities:
http://developer.android.com/guide/topics/fundamentals.html#lcycles