I want to pass intent value to fragment, right now in the activity i am getting the intent value through onNewIntent but i am passing the intent value through Bundle to Fragment but it's not working.
* MainActivity.java *
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
parseMessage = intent.getStringExtra("message");
if (parseMessage.length()>0) {
Bundle bundle = new Bundle();
bundle.putString("parseJson", parseMessage);
AbcdFragment activityFrag = new AbcdFragment();
activityFrag.setArguments(bundle);
}
}
@SuppressLint("DefaultLocale")
public class AllPagerAdapter extends FragmentPagerAdapter {
public AllPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch(position){
case 0:
return AbcdFragment.newInstance(getApplicationContext());
case 1:
return HelloFragment.newInstance(getApplicationContext());
default:
return null;
}
}
@Override
public CharSequence getPageTitle(int position) {
return CONTENT[position].toUpperCase();
}
@Override
public int getCount() {
return 2;
}
}
* AbcdFragment.java *
public class AbcdFragment extends Fragment{
public static AbcdFragment newInstance(Context context) {
AbcdFragment fragment = new AbcdFragment();
fragment.context = context;
return fragment;
}
@SuppressLint("InflateParams")
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.abcd_activity,container,false);
try {
parseJsonRes = getArguments().getString("parseJson");
Log.d("ParseActivityMsg", parseJsonRes);
} catch (Exception e) {
e.printStackTrace();
}
return view;
}
}
It's a viewpager fragment i want pass the intent value to AbcdFragment but i am getting null value in AbcdFragment.
Please kindly go through my code and suggest me some solution