can we display multiple activities in a single activities? - android

I want to know if we can display multiple activities in a single activity using ActivityGroup.
Can anyone please help me out with this ?
Thanks in advance.
Regards,
Serenity.

extend it to your activitygroup class.
Class A extends ActivityGroup{}
Get the LocalActivityManager
Set the content view as shown below
this.setContentView(activity.getWindow().getDecorView());
Where activity -> reference of the activity which you would like to display.
Class B extends Activity{
//in onCreate()
Activity activity = this;
}
As seen in coderanch.com

Related

share argument between all fragments

I am making a bottom navigation app and want to share data between all fragments, for example clicking a button to share a name for all action bars. With safeArgs I can only send data to one fragment.
And I want to ask, is any solutions for global arguments(global variables) like redux in react native or provider in flutter?
Thank you
You can use shareviewmodel, it's best practice
Link refer: viewmodel
EDITED
Just create a public variable as a class variable in your MainActivity
public class MainActivity extends AppCompatActivity{
public int myVar; // outside of all methods
...
Then you have access it everywhere in your Fragments inside that MainActivity, like this:
MainActivity mainActivity = ((MainActivity) getActivity());
if (mainActivity != null)
mainActivity.myVar = 15;

Access menu class from MainActivity class in android

I have two different classes. My main activity class and a separate menu.class. I want to be able to get the menu class to load from the mainactivity.class. The menu button does not work on my device or emulator when the mainActivity class is running. I am not sure how to call the menu.class from the mainActivity. I do not want to put the menu java code in the mainActivity.
I am asking for the way to add a snip of code to load a menu activity from one class to another, not to fix my code. I can not find any examples online to show how to load a menu class that is not also written in your main activity class.
public class lifeMenu extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.life_menu);
}
That is a snip of my menu activity. My main activity is called MainActivity
You can make your MainActivity extend your MenuActvity that entends Activity. Hard to know since you did not provide a snip of your menu class.

Calling a DialogFragment from a ListActivity

I have an android application with a main activity extending a listactivity.
public class Main_activity extends ListActivity {...}
Out of the options menu, I want to send a part of the items via mail. To select the items, I want to display a dialogfragment.
Everything works fine, but I have to start a new intent (loosing my listview), this extending FragmentActivity, as it is not possible to use getSupportFragmentManager out of the ListActivity.
startActivity (new Intent (this, Fragment_Activity.class));
and
public class Fragment_Activity extends FragmentActivity implements EditNameDialogListener {...}
Is there any possibility to display the DialogFragment directly from my Main_activity? What do I have to change?
I would suggest that you change Main_activity to extend FragmentActivity and move your list code to a ListFragment. With your main activity extending FragmentActivity it gives you the chance to show the dialog fragment without losing the ListView and the underlying data.
UPDATE: Since you don't want to change your current design I see two ways forward:
1 Move the list data out of the ListActivity and into a data model of some kind so that you don't lose it. Create a static class to hold the list data or store it in SharedPreferences.
2 Use a custom dialog instead of a DialogFragment

Android TabActivity instance in ViewGroup's chaild Activity

i have TabHost app with Three Activities,in first tab i created a viewGroup.every thing working fine
my problem is i want to get TabActivity instance from the view group's chaild Activity
How can i get this... i am trying like this in View group's child activity
Tab_Activity TabObj = (Tab_Activity)getParent();
abObj.someMethod();
i got Class Cast Exception,i think i am getting View group Activity instance,
i want to get TabActivity instance,please help me if any one knows answer
Tab_Activity TabObj = (Tab_Activity)getParent().getParent();
treid like this also...
Thanx in Advance
I just tested it: if your TabActivity properly extends the standard android.app.TabActivity then Tab_Activity TabObj = (Tab_Activity)getParent(); should work as designed.
EDIT: AH. You want to do something like this:
Tab_Activity TabObj = (Tab_Activity)((ChildActivity)getContext()).getParent();
from inside the ViewGroup.

How do I create common code for parts of Android activities?

In my application there are 14 activities. Out of that 9 activity contains custom title bar and tab pane. so here I need to write this common code at one place instead of redundant code in each activity that contain custom title bar and tab pane code (i.e layout and it's activity specific code)
What are the possible ways to do this?
The common way is:
Create a super class called, for instance, CommonActivity which extends Activity
Put the boilerplate code inside that class
Then make your activities extend CommonActivity instead of Activity:
Here a simple example:
public class CommonActivity extends Activity{
public void onCreate(Bundle b){
super.onCreate(b);
// code that is repeated
}
protected void moreRepeatitiveCode(){
}
}
And your current activities:
public class AnActivity extends CommonActivity{
public void onCreate(Bundle b){
super.onCreate(b);
// specific code
}
}
Hmm.. Common code doesn't always need to be in Activity class but just regular class. Than we could call those methods according to our needs referring to the common code class.
Am I right with this example?
Of course in case we need it like Activity, above proposal would work perfectly if we take care of Activity lifecycle and we don't forget to add it to manifest file.
In general Activities should just create UI, handle events occurrences and delegate business logic and/or other actions to the other components in our App.
Cheers

Categories

Resources