How to call startActivityForResult from ActivityGroup - android

I am using tab widget and each tab belong to a activity group. An activity group has several sub activities.The sub activites are added to the activity group via LocalActivityManager.startActivitY from activity group but now i want to use startActivityForResult from instead of startActivity. Can someone help me to accomplish that as LocalActivityManager class does not havestartActivityForResult method..

#Sabya i had been there in the same situation few weeks past. And i have found from my side that there is no way to use startActivityForResult in ActivityGroup. So i found some hacking type of technique to get out of this. First create a static variable of the result you want from startActivityforResult.After doing this,intent to a transparent Activity,in which you doing all those stuff of activityforResult.After getting value you set the value of the static variable that you created in the TabClass,After then finish the transparent Activity

Related

Best approach for accessing activities from another

I'm developing a simple home launcher. Main activity is the home layout, in it there is a button to call another activity to show the apps list. In this second activity, if you long press an icon, it adds to home screen.
So, from the second activity (apps list) I add an imageview to the main activity (home screen), but to do this I need to get the main layout, which it's not possible from different activity than itself.
To achieve this, I'm thinking different options like this:
1-Declaring a variable in the second activity:
public static RelativeLayout mainLayout;
Set it in the first:
// MainActivity
Intent i = new Intent(this, DrawerActivity.class);
DrawerActivity.mainLayout = (RelativeLayout)findViewById(R.id.mainlayout);
startActivity(i);
2-Using fragments avoiding the jumps between activities.
3-Changing the layout in the main activity (one activity for two layouts).
4-Declaring class descending from Application and store here everything I need in the different activities.
5-Use of broadcasters.
The question is: which is the right approach to achieve this ?
I've read several docs but there is no clear answer.
Definitely don't go with option 1. That's the best way to leak memory and context, and you don't want that. Resources associated with an Activity (in this case the layout) should be private to that Activity. This ensures that the framework can manage memory as it was designed to.
To communicate between activities, the official way is to pass parameters in the intent that launches the activity. You can add the identifier of the application you want to add to the main screen, and than retrieve the image either from the intent (as seen in the link) or if second Activity is launched for a result, then in the onActivityResult method of your home Activity.
However in you case I would suggest another approach. As you have to persist the layout of the home screen, I would create a database table containing the positions of the applications added to the main screen. I would modify the database entries where it's convenient and rebuild the main screen's layout every time it is displayed based on the database.

An Activity with two different Activities as Parent

I have an Activity DetailsActivity that is accessible from two different Activities: MapActivity and ListActivity. How should I implement Up Navigation to select proper Activity as Parent?
You can set a flag while going into the details activity from any one of the activities. Then onBackPressed you can fire that particular intent depending on the flag you first sent in.
I had the same problem and in my case rearanging the code worked perfectly. If you have the same logic in two classes, rather then inheritance, try to create another class, which will do the whole work for us.
Simple add a new atribute to Details Activity and (List Activity or Map Activity).

Can i access Manifest.xml data from my class file

Is there any way to change the parent of an activity from class file.
I have two activities say ONE and TWO, and both of them can start a new activity say THREE.
Now if ONE starts THREE, then for up Navigation parent should be ONE.
But if TWO starts THREE, then for up Navigation parent should be TWO.
If i can change the parent for an activity from my class file.
I will send some data from activities (ONE and TWO) to uniquely identify them then set the parent according to that data.
If there is any other way to do this then let me know.
I think you can only have one defined parent in your manifest but you could just send your parent when you launch your activity. Just pass a bundle with what activity launched your Third activity and handle it in OnBackPressed and if you want to change your up button handle it in onOptionsItemSelected.
In android activities are added in stack as they are started. Having said that, when you start activity THREE from activity TWO, activity TWO is added in stack below THREE. Now on click of up button in activity THREE, you can finish activity THREE and the control will automatically return to activity TWO.
Please follow this post for getting up button press in android. Now in its onClick case, you just need to finish activity THREE, and the control will return to whichever activity you came from. Whether it be ONE or TWO. You can finish the activity in onClick as following:-
Just write
finish();
in the case for home button

How do i add activity within activity?

i'm trying to make an app for nexus 7.
how can i display multiple activity to red area when the button is clicked??
Btn_A call activity A
Btn_B call activity B
Btn_C call activity C
Btn_D call activity D
i'm really need a example for this.
You should use fragments in this case.
You can find some useful examples in the API demos.
Tab activity is the best for that scenario. Please read the below link for tab activity.
http://www.androidhive.info/2011/08/android-tab-layout-tutorial/

How to pass paramters from Activity A, to the tabs of a TabHost(B activity)?

i'm trying to pass a parameter from a activity Main, to the tabs of a MyTabWidget activity.
How to do it?
Add data to the intent you are starting MyTabWidget activity and in onCreate() get the data.
Put example
myIntent.putInt("MyInt", 2);
Get example in onCreateMethod()
getParent().getIntent().getExtra().getInt("MyInt");
One way is to send a broadcast from the main activity and to register a BroadcastReceiver in your TabActivity. I don't think it is the best solution, but I couldn't find anything else that worked.

Categories

Resources