I have a main activity(M)(host activity) and few full page size fragments(f1,f2,f3).My main activity is a empty page and I am not showing anything into it. When app starts I am showing fragment f1 by default. But when I am pressing back button I am landing on white page of my main activity(M).I don't want activity M in my backstack .How can I remove that ?
I tried intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); before activity started but Its not working also I tried finish(); after start activity but it is also not working.Any Idea ?
Don't add the first fragment to the back stack. Then pressing back while on the first fragment will exit the application.
Related
I am working on an application with specific architecture regarding navigation. The situation I have right now is like this:
I have activity A. My activity opens activity B with function startActivityForResult().
After that on activity B is added fragment X.
Right now I am on fragment X and I detected the close button click and I transferred this event to activity B. Now I want to go back to activity A. The only way I see at this moment to achieve this is by calling 2 times function onBackPressed() in a row. This creates laggy animation in which the user sees removing of fragment and activity B in delay. This is bad for UX and looks bad in code.
Does anyone have some better suggestions?
on your fragment X button click.
button.setOnClickListener{ (activity as ActivityB).finish() }
or
button.setOnClickListener{ requireActivity.finish() }
My main activity have 2 buttons,say A and B
I always press A, and go to 2nd activity
Please tell how i can do this automatically, like when i open my app, main activity is on, button A pressed programatically, and what user see is activity2 ,when opening the app
PLEASE DONT TELL ME TO REMOVE BUTTON B,or USE 2nd activity only
Beacause some background threads are needed to be runned on main activity,
Write below code at the end of oncreate() of mainactivity... this will surely help you
A.performClick();
buttonA.performClick();
Add this code to your main Activity
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.
Have Activity A ,here am retrieving data from server .On click of button am finishing current activity and start B activity ,on click of button again i want to go A activity by finishing B activity but i dont want to reload A activity
You should have a look at the lifecyle of an activity and the activity stack. developer.android.com/guide/components/tasks-and-back-stack.html. To know more about the this developer.android.com/training/basics/activity-lifecycle/index.html. Go through the links and you should able to solve your problem.
I have 3 to 4 activities. It moves from 1 activity to another. If I am in 2nd activity then after pressing the back button of emulator it should be open the 1st activity. It opens also
but problem is both activities are connected to database. If in one activity any changes occur then it should appear in other activities.
So what to do here so that refresh of activity can be done in back button also?
you need to override the onresume of the activity you are returning to with your database