Specialize onOptionsItemSelected in a tabbed activity - android

I made a tab activity, menu logic is handled in the main activity because operations are the same.
I need to add a single line of code just for an activity for a specific option...is it possible to specify a general behaviour in the main activity and then, if needed , change something in sub activities?

Related

Android, Cicerone. Is it possible to implement cicerone with bottom navigation and Single Activity approach?

I'm using cicerone and single activity approach. When the application starts, the first three seconds I'm showing splash fragment inside my activity and so redirect to home fragment. Now I need to add to my application bottom navigation. Is it possible to add bottom navigation using single activity approach and cicerone. Or will I have to add another activity for the holding bottom navigation ?
Unfortunately, I could not find examples of projects with cicerone, single activity and bottom navigation.
My main goal is to save single activity, please tell me if it is possible to achieve this ?

MainActivity as Home destination in navigation graph

I have a simple application consisting of one MainActivity and two fragments, FragmentA and FragmentB. I want to use a NavigationGraph such that users still land on MainActivity but then can use two buttons to navigate to either FragmentA or FragmentB. Is there a way to do that? Based on the stuff on DAC, it looks like I have to use three fragments plus the MainActivity. But I was wondering if I can just use my existing scheme of 1 Activity and 2 Fragments.
Adding details to avoid confusion?
MainActivity has two buttons: User clicks on "Do A" to go to FragmentA and on "Do B" to go to FragmentB.
However, to use the Navigation Graph, it looks like I have to add one more fragment -- MainFragment. My question is: is there a way to avoid having to add an additional fragment and still use Navigation Graph.
Android applications need at least one activity to show UI. A fragment is just like a button in an android app. You cant show it without attaching it to an activity. In the android navigation tutorial, there's one activity. That activity only contains tag so it is actually empty. In fragment tag, you show a fragment and that tutorial show you how to switch fragment inside tag. So you are always inside MainActivity even when your app show a different UI(switching between fragment).
just like ianhanniballake comment above.. What does your activity show? What do you expect it to show? you always see it.
Edit:
Navigation graph only works for fragments. If you want to navigate between activities, use this Code:
Intent switchActivityIntent = new Intent(this, TargetActivity.class);
startActivity(switchActivityIntent);
You can use navigation graph like usual and when you need to open activity just use that code. It works fine.. But why do u need to use more than one activity when u using navigation graph? you should only have one activity when using navigation graph. That is why google make that thing(navigation graph) to support Single-Activity architecture.

Finished a set of activities, possibly in a task

In my app I implement a set of tabs to show activities instead of switching between fragments. All of these activities have a back button that I want to take the user out of the tabbed set of activities to where they were before they got to those screens. Is there a way I can easily finish all of the activities representing the tabs?
I looked into tasks but it seems like you can't just destroy a task and instead you have to start an activity in that task using CLEAR_TOP or CLEAR_TASK or something similar.
EDIT:
We use activities instead of fragments because each tab will be very large and complex/fully featured sections of the app that we thought would be better suited to an activity. The activities are started with REORDER_TO_FRONT. We do not want to use CLEAR_TOP since we would have to do a lot of requerying of data everytime we switched tabs. So for an example of the problem flow:
came from activity X and started activity A (the landing activity for the set of tabbed activities)
click a tab and switch to activity B stack looks like X->A->B
click third tab stack looks like X->A->B->C
when we click a "back" button on screen, all three activities should be removed from the stack so it becomes just X. But if we call finish it will make the stack look like X->A->B which we do not want.

Display Navigation Drawer in each Activity after connecting Fragments with Activities (Android - Github tutorial)

I am trying to implement a navigation drawer (left slide menu) in my Android project. My application has a main activity till now, in which you could navigate to others with Intent method through buttons.
So, I searched for a navigation drawer and I found/followed the exact steps of THIS tutorial. My code related to the menu is exactly the same, so for that reason, I am not posting it below.
Related to my code:
The three fragments that I created, were just extended the class Fragment and where completely empty.
The ONLY change from the code in the tutorial, is inside the res/layout/activity_main.xml, because I changed the com.codepath.examples.navdrawerdemo.FragmentNavigationDrawer to 'my_project's_name'.FragmentNavigationDrawer.
What I managed to do:
I managed to create the menu that I want and display it ONLY if I make the MainActivity.java as the launcher inside the AndroidManifest. When I see the menu, I can go to each fragment through it, but I can't go to any of my Activities because I didn't link the fragments with the activities that I want. My menu, also does this transition that it should, so I am completely fine with the style of it.
What I want to do:
I just want to have the same menu inside every activity that I have already created, and when I click in an item in the menu, I want to navigate to an activity that I want BUT I want the activity to still display the menu.
I searched for solutions, but when I put back my first Activity as launcher in the Android Manifest, and set a layout for example inside the Fragment for it, it's just a useless layout. And when I tried to do an Intent to call my Activity inside the Fragment, the menu disappeared.
P.S I didn't changed any of my Activitie's code or of their layouts. I added only the code from the tutorial!

keep activity going in background when switched to another activity?

I have my main activity going and a button going to a different activity. When I go to the other activity my main activity stops. How would I keep the main activity going?
Thanks in advance.
How would I keep the main activity going?
You wouldn't.
Depending on what it is that you are doing, you might consider moving it to a Service.
Yes, you can keep your main Activity running. My way is use a "CHEAT".
Example your main Activity is A, in A we have button btnA. Click this btnA will open activity B.
You create a tab bar with 2 tab contains A and B. After initialize tab bar, call
tabHost.getTabWidget.setVisibility(View.GONE);
to hide this tab. So you only see main Activity visible.
When btnA is clicked, only need to switch tabHost to B
tabHost.setCurrentTab(1);//1 is index of Activity B
This question & answer is similar with your question. You can refer to it.
Activities and sub activities

Categories

Resources