I want to close the android application from fragment activity. Fragment layout contains two menus.one of the fragment will display the list. When we click on the list it will display the details for list in Dialog Alert that alert box contains two buttons.if you click one button it will open another activity that activity will contains list. if we click the list it will open previous activity in the fragment activity.if you click back button from this activity it is not closing the app completely.
please give me good solution to exit the app from the situation
As i understand you activity managment is something like this:
A -> B -> A
And if you pressing back now it is not closing.
You should watch to Intent.FLAG_ACTIVITY_CLEAR_TOP
So when you opening Activity A again you code should look like this:
Intent a = new Intent(this,A.class);
a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(a);
Related
I have an activity which holds 3 fragments and in the last fragment i show the accesibility dialog to turn on the service for my app , the issue is when i move back from the settings dialog , it does not redirect me to the last fragment from where i started the dialog , instead it restarts the activity .. i would like to find a solution on how to redirect from settings dialog to the last fragment in my activity , Thank you
Settings Code
val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(intent)
When user click on a notification, I set up a backstack of Activities A -> B, where B is on top and shown to user. I would like the lifecycles of Activity A to run, so that when user presses back button and comes to Activity A, it is already ready. What could I do to achieve this?
This cannot be possible as android will not allow us to do that, the only way I can see you can achieve this by doing your Activity A operation inside your Activity B And provide those details to Activity A when the user pressed back button.
Note: If you are showing any kind of list on Activity A or doing similar kind of work, you can have one Singleton Class where you can get your data in Activity B which required by Activity A, and provide same data to Activity A when the user pressed back button.
You should open the activity as normal but then put this line of code in the OnCreate() method to bring to the back.
moveTaskToBack(true);
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.
I have a homescreen in my app that doesn't have any tabs. It just has a series of buttons. Clicking a button launches the new activity that contains a tabbar at the top. This functions normally. I can click through all the tabs just fine. What I'd like to do though is add another tab that doesn't really have content but instead, when clicked, will take the user back to the homescreen. Is this possible, and if so how would I go about doing this?
What about just closing the "tabbar at the top"- Activity with finish(). Your homescreen is right under if you did not finish() it. This is IMHO the most basic way to navigate in Android.
Another way is from your "tabbar at the top"- Activity you could do this
Intent intent = new Intent(this,homescreen.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
This should kill your "tabbar at the top"- Activity and start homescreen activity if it's not started. If it's started it will pop up
Check this How do you use Intent.FLAG_ACTIVITY_CLEAR_TOP
Is it possible to open any acticity on the current tab by clicking the current tab itself?
What is to be done in my application:
user performs a search , a listactivity is displayed on same tab(Using TabGroup activity). Then If User presses the same tab, again the search page should open.
Is this possible?
Try this,,,,
Rather than starting two activities, you perform both in same activity.
On pressing tab show search activity.
show search screen, when user clicks search, get your search result and set it as current activity view i.e, setContentView(list);
when user clicks search again start SearchActivity again (as usual).
Refer this link:
Launching activities within a tab in Android
In first answer,you can set SharedPreference Variable and then check for that variable to know which activity to be loaded in this tab(in YourActivityGROUP class).you can set Extras to Intent accordingly in your main activity which you use to open an activity in a tab. (I haven't tried this,but i think,this will solve your problem.)