Note that there are some explanatory texts on larger screens.

plurals
  1. POIntent within fragment works only half the time
    primarykey
    data
    text
    <p>I am trying to pass an intent with data from Activity A to FragmentActivity B to Fragment B. A button from Activity A starts 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 the time. </p> <p>I have no idea what causes it to filter just some times and at other times it just returns the whole table unfiltered. I am guessing it has to be related to the intent I am using in the fragment because the filter worked without issue in the version of the app without the fragment. It also seems inefficient the way I am sending the intent from Activity A to FragmentActivity B to Fragment B. How can I fix this problem?</p> <p>Activity A:</p> <pre><code>Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setClass(FindMovie.this, ShowMovies.class); intent.putExtra("year", year1); startActivity(intent); } }); </code></pre> <p>FragmentActivity B:</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_show_movies); if (getSupportFragmentManager().findFragmentByTag(TAG) == null) { final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.add(android.R.id.content, new ImageGridFragment(), TAG); ft.commit(); } Intent i = getIntent(); year = i.getStringExtra("year"); //resend through another intent to the fragment B Intent intent = new Intent(getApplicationContext(), ImageGridFragment.class); intent.putExtra("year", year); } </code></pre> <p>Fragment B:</p> <pre><code>@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.image_grid_fragment, container, false); Bundle extras = getActivity().getIntent().getExtras(); year = extras.getString("year"); return v; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload