Friday 15 May 2015

android - Intent within fragment works only half the time -


I am trying to pass an intent with data from Fragment Activity B to Fragment B. from Activity A. A button FragmentActivity B. The "year" string sets a filter with which I query a mysql database on a remote server. The code below works but only half time.

I do not know that this is due to filtering for a while and the second time it gives the complete table unfiltered. I am convinced that it should be related to the intent to use this section because this section was filtered without working in the app's version without any limitation. It also feels disqualified that the way I am sending Fragment B. to Fragment Activity B from Activity A. How can I fix this problem?

Activity A:

  button button 1 = (button) Find VVBIID (R.B. button 1); Button 1. setOnClickListener (New OnClickListener) {@Override Click Public Zero (see V) {Intent Intention = New Intent (); Intent.setClass (FindMovie.This, ShowMovies.class); Intent.putExtra ("year", year 1); Beginner (intent);}});   

Fragment activity B:

  @ Override Protected Zero on the Crate (Bundle Saved InstantState) {Super.Nuke (Saved Instance State) ); SetContentView (R.layout.activity_show_movies); If (getSupportFragmentManager (.) FindFragmentByTag (TAG) == faucet) {Final piece transaction feat = getSupportFragmentManager (). BeginTransaction (); Ft.add (android.r.id.content, new ImageGridFragment (), TAG); Ft.commit (); } I = getIntent (); Year = i.getStringExtra ("year"); // Reopen again with the second intention of the segment B. Int = intent (getApplicationContext (), ImageGridFragment.class); Intent.putExtra ("year", year); }   

Fragment B:

  @ Override public view creatives (LayoutInstallter Inflight, View Group Container, Bundle Saved Instantstate) {Final View v = inflater Inflate (r) .layout.image_grid_fragment, container, incorrect); Bundle Extras = getActivity (). GetIntent (). GetExtras (); Year = additional .getString ("year"); Return vi; } 

I think this is a thread timing problem, creating your fragment active piece, which will be sent to a thread (I think) And then you are adding new value to the original thread, and sometimes the second thread is enough to execute FragmentB onCreateView before getting the new value during what you can do during the FragmentTransaction add value to 'year' .

  @Override Secure Create Zero (Bundle Saved InstantState) {// Create a new piece and bundle piece slice = New ImageGridFragment (); Bundle bundle = new bundle (); // Enter the variable in the bundle and add it to the piece bundle.putstrings ("year", getIntent (). GetStringExtra ("year")); Fragment.setArguments (bundle); // Insert piece slice manager slice manager = getSupportFragmentManager (); Fragmentation manager Babatinection () .add (android.r.id.content, fragment) .commit (); }   

in 'year' is found as:

year = getArguments (). GetString ("year"

Cheers.

I think this will solve this issue, I know what happened,

Cheers.

No comments:

Post a Comment