How do I open another activity with the same button I clicked earlier? For example, I click button A and goes to Activity 1 and I click home and click button A again and must go to Activity 2.
I tried putting id on button in xml and call different activity on its java.
Imagine if the button is from HomeActivity,let the launcher activity pass an ExtraKey to the HomeActivity and again another ExtraKey at the OnBackPressed of the Activity you are navigating to after clicking the button.Set the onClickListner according to the String passed by those activities.
Related
https://github.com/oneHamidreza/MeowBottomNavigation
i have implemented bottom navigation bar using above library but when i press back button it is directly closing the app even when i am in another fragment alsp.
please guide me that when i press back button it should come to home fragment and when i am in another fragment the back button should work accordingly to that respective fragment.
when i press back button in bottom navigation bar it should come to home fragment if it is in another fragment other than home if it is in home fragment then it can close app.
I have 3 activities let's say MainActivity, Activity 2, and Activity 3.
In the MainActivity I have a button (start/stop) when I click on this button an animation start but when I go to activity 2 or activity 3 and I comeback to MainActivity the animation stopped by itself.
But me I want that the animation of the MainActivity never stop until I click the button stop.
I tried this code in AndroidManifest.xml but it doesn't work.
android:launchMode="singleInstance"
If you go back from MainActivity then your Activity will be Destroyed if you do not fire an Intent in onbackPressed() regardless of launchMode.
launchMode are instruction for how the activity should be launched. On stack pop it will destroy anyway. Read launchModes .
Solution:- Solution to your problem SharedPreference. Save the current state of animation and restart it with previous state when Activity relaunched.
I got 2 Fragments. In the first Fragment I got a button.
How is it possible to duplicate the button on the second Fragment when the user click on it.
What do you mean by duplicating a Button? If it means creating a Button with the same text or other layout attribute, you can create a method in the second Fragment, like createButton(String text, int color), to add the button dynamically. When the button is clicked, find the second Fragment, cast it to the class of second Fragment and call the createButton method.
If I have Activity A and Launch Activity B from it, then press home I go back to home screen. If I launch the activity again from the recent apps, it goes back to B as it should, but when back is pressed the Activity send me back to the Home screen not Activity A. Activity A and be are alive for the entire time. How can I make the back button function as expected? Thanks.
Don't call finish() on Activity A if you want the back button to go from Activity B to Activity A...
Pressing the Home button empties the Activity stack.
You can capture the Back button and make it do what you want, but you would have to implement your own stack of previous activities.
I have an Activity which displays an alert dialog priot to the content.
Also a search activity is called before this activity.
Now when i press back on this activity i am lead to a black screen (which i assume is eighter because of the dialog [unlikely] or from the search activity). Only when i press BACK twice i get to the activity i was before.
How can i get rid of this?
Thank you.
This phenomenon was caused by the search activity. to avoid this i simply added android:noHistory="true" for the Search Activity in the Manifest.