How to move activity to another activity with specific fragment target? - android

Is there a way that from the activity i want to go to another activity with multiple fragment and select a fragment that i want to focus it.

Assuming you want to move from Actvity A to Activity B and make Activity B show a particular fragment. You need to pass an extra containing some form of identity(Eg. the name you gave to your fragment) of the fragment you want to show to Activity B. Then in onCreate in Activity B read the extra you passed to it to determine which fragment to setup in Activity B

Related

Update viewpager fragment specific position and get back to previous while backpress

I have a view-pager with two fragment in it . based on my logic i want to replace the fragment on a specific position with another fragment but when user back-press i want to go back to previous fragment i replaced with it
for clearance
i have 4 fragment A, B, C, D initially i added A and B to view-pager, then i replaced B with c in view-pager , So that i want is to go back to fragment B (replaced by C) from C (current) while pressing back button instead of going back to another activity
you can do using assign constant variable to your fragment or assign tag at time of Fragment Call.
I manage using VariableName CurrentFragment which update value on Fragment Lunch. Then after onBackpress method of your activity i handle the fragment based on Constant Variable.
Visit below Stackoverflow link where i put solution step-wise to handle multiple fragment on backpress.
Click Here to View StackOverFlowAnswer

how to launch a fragment of an activity from another activity?

I have one activity 'A' which has many buttons on it to call several corresponding fragments of another activity 'B'.
Activity 'B' contains a navigation drawer where i have created fragments for all the items that we have in the navigation drawer.
So, how do i immediately launch suppose 'fragment 1' ( i.e one of the items of the navigation drawer), inside Activity B, when Activity A calls Activity B.
Add an extra to your Intent which defines which Fragment should be loaded.
intent.putExtra("fragment","FragA");
In your onCreate in Activity B:
String fragment = getIntent.getStringExtra("fragment");
// Do something to load correct fragment

Android 3 Activitys - how to hande passing data?

So I just want to clarify the life cycles a little. I have three activitys A(main), B and C. B is startet from A with some extra infromation, that it needs to show the correct content. Now B starts the Activity C (no extra content needed).
Can now (Activity C is in foreground) activity B be killed? If so, when pressing the back button, do I need to transfer that same infromation from C -> B, that was transfered at the first creation of B? Basically, what I wnat to know is, if extra content is used to start activity from parent activity, should this same extra content be used to start the activity from its child?
Thank you
Jaka
No need to pass back data from C -> B when you press back button.
On B's onCreate, store the additional data into private class variables and you can use it when the activity is restored.

Passing value to dialog that's running from another activity

In my project I have an activity A and a dialog A1 inside A. From A1 I can call to activity B. In activity B have some string value I want to get and set it on Edittext in dialog A1 that had value already when finish activity B.
How can I do that?
Make a DialogFragment. Add it to the screen with a FragmentTransaction when the dialog needs to be shown. Either keep a reference to it while it is showing, or give it a tag when you add it so that you can find it later by its tag.
Use StartActivityForResult to start the next Activity.
Use onActivityResult to get the result of the second Activity. If the dialog is showing, use some public method you define to manipulate it. If it's not showing, you could just show it again with the new information.

how to update the Activity when press back button in android?

In my android apps i have four activity A->B->C->D and in every activity i call web service then update the list-view and other element from the server so suppose i did delete some data from the database for Activity A and if user access the Activity B and he press the back button then Activity A should be refreshed. I did override onResume method and check the data is updated or not but didn't worked. I also tried another way but not achieve my goal.
my Activity structure is like a following
Class A Is Fragment which is having two tab and each tab contain listview
Class B Is Activity
Class C Is Activity
Class D Is Activity
I don't understand how to call web service again when press the back button and how to update fragment and activity when user press the back button. Please anybody suggest me some answer.
Thanks in advance
you can override the OnBackPressed-method. check the top-answer on that link!!
Android: Proper Way to use onBackPressed() with Toast
Start activity B from activity A with "startActivityForResult" instead of "startActivity".
In activity B you defaultly return RESULT_CANCELED -> so setResult(RESULT_CANCELED). Only when activity B is finished on purpose you return RESULT_OK.
In activity A you then just need to implement onActivityResult(). Depending on the result returned from activity B you can then do specific stuff in activity A, in your case refresh something.
Here is an example: http://www.vogella.com/articles/AndroidIntent/#usingintents_sub

Categories

Resources