Can i access Manifest.xml data from my class file - android

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

Related

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).

How to change Activity in Android with Xamarin?

I'm new with Xamarin and I'm tring to create an Android App.
I have created a 2 Views related to 2 different Activities. The first Activity, name it A, has a button that launches the second Activity, name it B.
B has an EventHandler that is connected, in the OnCreate method, to A's Event. The EventHandler print on console a string, that's it.
if I launch the app and press the A's button, the B activity appears. Now, if I press the Back button the A Activity appears again, after that I press the button again and the B Activity appears but this is a new B Activity istance and not the previous one. I can see that because the OnCreate method is called twice and because I can see on console that the event is called twice.
If I repeat this many times I can see the same string printed on console repeated many times. I would like to have only one instance of any activity, so I need to change view without creating more istances of one activity that was already created or destroy the B Activity when the Back button is pressed.
How can I do that? is it the right way to do it?
You can't link the two activities, or better, you really shouldn't. If you need shared data then go through static properties (perhaps in a separate static class).
Read about activity lifecycle and activity launch modes. Note that you are probably creating a wrong flow though.
I think in order to get what you want (having two "Activities" of which the instance is always the same when you are switching between them), you basically need to use Fragments instead of Activities, in a FragmentPagerAdapter.
http://developer.xamarin.com/guides/android/platform_features/fragments/part_1_-_creating_a_fragment/
FragmentPagerAdapter Exists Only In Android.Support.V4.App (and not Android.App)

how to access button/view of an activity from another activity

I have a button in an Activity and when on clicking this button, some operation will be performed in another activity. And I should call the buttonclick event in 2nd activity only.Simple saying, I have a TabActivity with button and upon clicking the button some operation should be performed in the underlying tabs. ButtonClick event should be in the tab.
How can I achieve this?
create one common function in a helper class and call it from both the places.
You could broadcast an Intent from your first activity to be received by your second activity. When your button is clicked, it's parent activity broadcasts a unique intent which your android manifest will route to your second activity for receiving.
There is a good example of that here:
http://thinkandroid.wordpress.com/2010/02/02/custom-intents-and-broadcasting-with-receivers/
However, have a look at the android reference and consider using a LocalBroadcastManager which is more appropriate if you are just broadcasting within your process.

Android Multi-Screen Application

How do you handle multiple screens in an android application? I have developed with the tab bar at the bottom without problem, however what I am wanting to do is replace all the content on the screen with the content from a new .xml layout file I have created in the project. Additionally, how would I tie the back end code to the new layout file? I'm sure this question probably exists already and is googleable (may have made up a new word). However, I don't know exactly what it is that I am looking for. Thanks in advance for your help.
What you need to do is, create a new Activity and add it to the AndroidManifest.xml:
<activity android:name="ActivityClassName" android:label="Label for the Activity"></activity>
and can be called in a method:
public void startActivity() {
Intent someName = new Intent(CurrentClass.this, ActivityClassName.class);
startActivity(someName);
}
Android applications generally use a separate Activity for each screen, and switch between them using Activity.startActivity and Activity.startActivityForResult. You can pass arbitrary data to an Activity via Intent.putExtra.
Hope this helps,
Phil Lello
It really depends on how you want your application to flow.
Let's consider the scenario where a user does the following:
Starts your first activity
Presses the 2nd tab
Presses the 3rd tab
Presses the back button
If you use a separate activity for each screen, then the following would happen
Activity 1 is started
Activity 2 is started
Activity 3 is started
Activity 3 is closed, user returns to Activity 2
(in this case pressing the back button again would you take you back to Activity 1, and pressing it again would exit your application)
If you used one activity for all the tabs, then the following would occur
Activity 1 is started
Activity 1 sets tab content to tab 2 content
Activity 1 sets tab content to tab 3 content
Activity 1 is closed, user returns to home screen
If you are using a screen with tabs, then the second method (a single Activity with a TabHost or similar) is the preferred method, otherwise the user will end up making a large activity-stack just switching between tabs (meaning if they switch between tabs a lot they'll have to press the back button a lot of times to exit).
If you want to go for the single activity approach, then do some research on TabHost and TabContentFactory. In the createTabContent method of your factory you can inflate a View/layout from XML to set as the tab content using View.inflate. Look those up and come back ask another question if you get stuck ;)
i think you may want to play with more than one activity.... you can have multiple activities and one xml for each of them... in this way you can have different screens... check these links. Multiple Activities, Creating an Activity.... hope this helps...

Activity launches transparent Overlay Activity. How to pass Data without closing the Overlay?

in my app i am having an Activity that launches another Activity ontop of it. The second Activity is meant to provide controls like next and previous for the first activity.
How can i pass button events between the two activities that are visible at the same time without closing the Activity with the controls?
You can send Broadcast in order to communicate between Activities.
In parent Activity register BroadcastReceiver, then send a Broadcast by calling sendBroadcast(..) in child Activity.
It sounds like what you are trying to do doesn't require two activies, but rather additional view objects on the main activity that will be shown/hidden/removed/added as buttons on this activity are pressed.
If you need additional help, I would recommend elaborating on your original post.

Categories

Resources