Hello Android developers,
I'm trying to pass arguments between two distinct activities but I've got stuck into an issue and I can't get out of it.
Basically, I'm trying to pass two strings from a fragment contained in my MainActivity, MainFragment to my secondary activity, SecondaryActivity
I can pass those two strings from Other Activities to the SecondaryActivity without issues. I can even do that from my NotificationService, but I can't from that specific Fragment.
Debugging, I can see that the first string I pass has been received correctly but the second one has been not. Variables are also set, so I'm not trying to pass something "null", I checked that on the debugger.
Here's part of my code.
MainFragment.java (Sender)
public class MainFragment extends Fragment {
public MainFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_home,
container, false);
final TextView firstStringToPass = (TextView)view.findViewById(R.id.first);
final TextView secondStringToPass = (TextView) view.findViewById(R.id.second);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Intent secondaryActivityIntent = new Intent(v.getContext(), SecondaryActivity.class);
Bundle args = new Bundle();
args.putString(SecondaryActivity.ID_FIRST_STRING, firstStringToPass.getText().toString());
args.putString(SecondaryActivity.ID_SECOND_STRING, secondStringToPass.getText().toString());
secondaryActivityIntent.putExtras(args);
getActivity().startActivity(secondaryActivityIntent, ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle());
}
});
return view;
}
}
SecondaryActivity.java (Receiver)
public class SecondaryActivity extends AppCompatActivity {
public final static String PLAY_WORD = "com.etc.author.appname.STRING1";
public final static String PLAY_IPA = "com.etc.author.appname.STRING2";
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.secondary_activity);
Intent intent = getIntent();
Bundle args = intent.getExtras();
first_string = args.getString(ID_FIRST_STRING);
second_string = args.getString(ID_SECOND_STRING);
....
}
....
}
Any help would be very very appreciated.
Thank you.