For some reason clicking the App over view button (the button next to the home button and lets you view all apps running) makes my app flicker... What would be the reason?
I am currently using one activity, all other screens are fragments stacked on each other. Could that be the problem?
Also, when clicking on the app over view button, sometimes all the fragments will simply be removed leading me back to my singular main activity...
Related
I have two fragments (for ex. fragmentA and fragmentB).
first , in fragmentA use findNavController().navigate(R.id.action_fragmentA_to_fragmentB) to navigate to fragmentB .
then , in fragmentB if you want to back to fragmentA. there are two ways in below :
just press back button : fragmentA's onCreate() won't be called
findNavController().navigate(R.id.action_fragmentB_to_fragmentA) : fragmentA's onCreate() will be called
why?
The reason that the back button doesn't call onCreate of the fragment is by design. Users would not expect the back button to call the onCreate, or create, your fragment again.
As an example, think about when you open the YouTube app on Android and you are shown your home screen, populated with videos based on your interests. When you tap on a video after a bit of scrolling and then midway through the video decide to go back by pressing the back button, you expect the app to go back where you tapped on the video, with the same amount of scrolling you had done, instead of reloading your entire home page again filling with new videos and resetting you to the top of the screen.
Similarly, back button in your app should do the same. If however, you want your back button to behave differently, android does provide a way to do this. Refer to this for that.
I would like to create activity in which it would be explained how the app is supposed to be used. On a click on a button, I would like an Activity to be opened which has next and previous buttons on the bottom. So the first screen after the click on a button would show the first instruction and you can press next to see the next instruction which opens a new screen. After going through all the instructions, I would like a Finish button to return back to the main activity.
My question is can this be made in a single activity or is it actually more activities that differ only by the text and pictures they contain?
Yes it can be done in only one activity(actually 2 if you include the main activity).
What you can do is have multiple TextViews, and when the next button is pressed, you can toggle that 1st instruction's visibility
. And so on for the next instructions. The Next/Previous buttons should determine what Textview is currently visible, so they can keep track what Textview to show next. Use switch statement
I am making an android app. In the action bar, I have three buttons: the up button, a button that goes to a home page (essentially a restart), and an info button that describes the app.
I have set the info button to go to an activity called 'info activity' that just has some text on it. The issue is this problem: My info activity can be triggered by multiple activities in the app, so this activity does not have one parent I can name in the Android manifest for a return. I cannot find any documentation to allow one activity to return to multiple activities, depending on which the activity the 'info activity' was accessed from and use the up button navigation to return to it. Is this impossible? Or is there another way I can do what I am attempting? It seems like one activity can only have one parent.
The "Up" navigation is designed to work in a hierarchical structure and by that, I guess that means predefined structure. It's not meant to work for dynamic, ad-hoc structures.
From Android designed guide:
The Up button is used to navigate within an app based on the hierarchical relationships between screens. For instance, if screen A displays a list of items, and selecting an item leads to screen B (which presents that item in more detail), then screen B should offer an Up button that returns to screen A.
If a screen is the topmost one in an app (that is, the app's home), it should not present an Up button.
When an application has a single view, the Back button probably resumes whatever previous application was running/suspended. I'm tempted to provide an explicit button which says 'Back' right there on the UI ...
Should I provide an explicit back button in my view, or should I simply override the navigation button provided by the OS? My gut says the latter would be counter-intuitive. Are there any recommendations on this by the android community?
That entirely depends on your application. Normally, your application is made out of multiple activities (Activity objects), and the back button will go to the previous activity.
So if your app has a main menu (activity A), which has a button to go to search (activity B), which will lead to search results (activity C), then pressing the back button on the search page gets you back to the main menu. This is fully automatic, you don't need to write anything for this to work.
That's how Android works, and that's how you should write your app. All Android devices have a device button (physical or on-screen, in case of Honeycomb), so don't waste precious screen real estate on a "back button". Don't be like the iPhone.
How do I go to previous screen from current screen in Android app? I know there is a back button on phone, but it takes me to beginning screen of my app and I want my buttons on app to work for going back to previous screen.
Back button indeed takes you to previously seen activity on screen, that launched the current one (not by means of back button). If back button takes you to beggining screen of your app means that navigation to your last activity was done from it. Try launching an activity from another one different from start activity.
What really can be problematic is ending application once at start activity by pressing back button and discovering the application switching to activity that lauched start activity (not by means of back button). In this case you should just call finish() inside onDestroy() listener method of your start activity.