Android: many activities on single screen? - java

I'm creating my first app for Android device and I was faced with a challenge... I want to create fixed bottom bar on every screen of my application (something similar to bars from tunein radio).
However I do not know how to make bars which are fixed on every activity (bar do not load when new activity is loaded but is permanent on every app screen). I do not want to <include> my bars in every activity (I've tried this solution but my bars were loading with activity).
Is it possible that this is Activitygroup and only middle activity is changing? If so how can I do that?
PS.
What book or tutorial do you recommend ;-)?
tunein radio bottom and top bar image #1

Use fragments api. It perfectly fits your needs.

Look at ViewFlipper. It lets you manage multiple views. You'd have one activity that would watch your button bar and flip views in response to buttons.

Related

How to Show Custom View (FAB) On All Screen in Android

I want to show my custom floating button on all screen in my app without putting it in each activity.
Do we have some Global Activity like put a code once will show the Custom View all screen and hide/remove when app killed
I tried lot of things like Screen Overlay display over all apps
Please check code here - How to display custom view on all screen in android from my library
I've never tried to do it the Java/Kotlin way. But have you considered using Fragments?
You can declare xml layout and code for one Activity with a FrameLayout container and an FAB. The container holds all your screens and they switch between each other in the container. The FAB is on top and therefore will be displayed no matter the screen.
The Activity has a reference to any screen that might be displayed in it, so the FAB can behave accordingly.
Not sure if this helps. Perhaps if I see some pictures, I could suggest better.
Related Read:
Creating a fragment: here
Fragment Transactions: here

I don't understand how to organise my fragments

I have realised an NFC reader application
So i have 3 activities :
MainActivity, which is an activity who contains a Button. If button is clicked, the scan is activated and the user can put his NFC tag against the device to detect it.
WebActivity, who is launched if the NFC tag contains and URL (and open a WebView) or if the user want to launch WebActivity by himself
HistoryActivity, who gonna contains a list of every scans.
Now, I would like to swipe activity with a finger gesture. according to my research on Internet. I need fragments and ViewPager.
But every example that I saw is bases on ONE activity and multiple fragments.
But in my case, I have to create 3 fragments (one per activity), right ?
And I really don't know how to manage my fragment. I mean, what to put inside ?
All I want to do is create a transition/animation while changing activity... That's crazy
This is too broad of a question but hopefully my answer will steer you in right direction.
You should definitely go with single activity/multiple fragments model. Aside of recommendations by Google, you could use navigation components, deep linking much easier then without single activity.
Yes you should be using ViewPager for the purpose (and likely your implementation of FragmentPagerAdapter as well) however I do not understand what kind of swiping will you be doing
Reading your setup, I would suggest to use bottom view with 2 items (good example is here https://github.com/android/architecture-components-samples/tree/master/NavigationAdvancedSample/app/src/main/java/com/example/android/navigationadvancedsample). 2nd one would show history, first one would offer a button that activates your action, and then displays fragment with your WebView.
As a side effect of such implementation, you'd be able to go back from 2nd bottom view item to whatever first one holds - by pressing system back button - which I think is nice touch.
UPDATE to "swiping takes place anytime. " comment:
You could have single activity, ViewPager with 2 fragments. First fragment would display a button, 2nd fragment would display a history. You could freely swipe between them, as you want to. However to me it does not make sense to put WebView screen into this. WebView screen is result of action (NFC detection) and it should probably display as full screen, without any chance of swiping between main/history and itself. Hope it helps or I'm missing some important piece of info you did not share.

What object let's me have two different components on the screen at once?

I'm trying to make a minesweeper game and I sort of want it to look like this.
To clarify, I want there to be a top object so I can place the timer, the number of mines left, and the smiley face button on it (I do not want to put these on the action menu).
And the bottom object be the actual game (I already made this as a Table Layout).
The problem is, I don't know what kind of object I should be using for this. Fragments? Activities? Layouts? What do I need to accomplish this?
I do not want to put these on the action menu
Then you need to decide between Activity & Fragment. Layout is common for both Activity & Fragment which need for views.
If you use fragment then it may be little hard to implement because you constantly communicate between your table fragment & timer fragment. But advantage you found that you use it more flexible way for different device size.
I think it is easy to implement in activity. Just need vertical Linear Layout to separate your table & timer.

Changing background colors affects unrelated views in another activity

I'm currently having a really weird issue in an Android app I'm developing.
The short story is that background colors I set programmatically in one Activity are appearing on completely unrelated views in another activity.
Basically, in one Activity I have a ListView in which the user can select or unselect any item by tapping it. When selected, an item is highlighted with an orange background. This background color is set programmatically via a ListAdapter.
The user may then navigate to a second Activity with a completely different layout in which every view is supposed to have a white background (this is set in the appropriate style/layout xml files). However, sometimes, the entire background of this second Activity turns the same orange color as the highlighted ListView items in the first Activity. Nowhere in the second Activity are background colors set programmatically, so I have no idea how they're changing color at all, let alone why they're turning orange.
If that's not weird enough, it only consistently happens on one device (a Droid Razr Maxx with Android 4.1.2) out of the 10-15 devices of varying manufacturers and Android versions I've tested the app on so far. Other than on that Razr, I've only seen it happen once on one other device. And even on that one, after selecting/unselecting different ListView items and going back and forth between the Activities a couple times, the issue disappeared and I couldn't reproduce it again.
Anybody have an idea what might be going on?

java android view structure

Just a simple maybe stupid question.
Is it ok to use multiple activities at once in an android application using an Inflater? I want to have multiple views on my screen without losing the previous view. For example, a user clicks on a button and a information screen shows up. Start Intent would convert the whole screen to the information screen activity.
Using an Inflater works but I'm just wondering if its the right way to display multiple views. Thanks in advance.
You should be using Fragments for this. Each fragment has a view/layout and you can move them in & out of your main view as you require. There are many tutorials
You can set the visibility of the views, e.g.:
Button b = (Button)findViewById(R.id.button);
b.setVisibility(View.GONE);

Categories