-2

I have 2 spinners in Blankfragment.java and I want to send the key of intent.putExtra(Category1) or intent.putExtra(Category2) and receive them in the same activity aaa.java

by getIntent().getStringExtra("Category1"); or getIntent().getStringExtra("Category2") in switch case or if statement

but I cant do this because I can't use more than one getStringExtra in aaa.java

please help me

Code of Blankfragment.java:

  int spinner_pos = spinner.getSelectedItemPosition();  
  int spinner2_pos = spinner2.getSelectedItemPosition();


  if (spinner_pos == 0 && spinner2_pos == 0) {
    Intent intent = new Intent(getActivity(), aaa.class);
    String a1 = null;
    intent.putExtra("Category1", a1 );
    startActivity(intent);
  }
  else if (spinner_pos == 0 && spinner2_pos == 1) {
    Intent intent = new Intent(getActivity(), aaa.class);
    String a2 = null;
    intent.putExtra("Category2", a2);
    startActivity(intent);
 }

Code of aaa.java:

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_aaa);
     .
     ..
     ...

   //need to use 
    getIntent().getStringExtra("Category1"); .. // for if -> "01"
    and 
    getIntent().getStringExtra("Category2"); .. // for else if -> "02"

  //in this if statment

    if(// write something) {  
            loadListWorkers("01");  
    }
    else if (//write something) { 
            loadListWorkers("02");    
    }

 }


 private void loadListWorkers(String placeId) {

   adapter = new FirebaseRecyclerAdapter<workers, WorkerViewHolder> 
           (  workers.class
            , R.layout.vh_worker_item  
            , WorkerViewHolder.class  
            , workerList.orderByChild("Worker_place_ID").equalTo(placeId)
           ) 
   ...
   .....
   .......
   .........
Rohit Singh
  • 16,950
  • 7
  • 90
  • 88
  • 7
    Possible duplicate of [How do I pass data between Activities in Android application?](https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application) – Tamir Abutbul Jan 27 '19 at 18:40

1 Answers1

0

Change the logic in you aaa.java. Check if Incoming Intent is not null.

Intent cameFrom = getIntent();
if(cameFrom != null){
  //Here your intent isn't null now let's check for the values
   if(cameFrom.hasExtra("Category1")){
       cameFrom.getStringExtra("Category1");
   }else if(cameFrom.hasExtra("Category2")){
       cameFrom.getStringExtra("Category2");
   }else{
      //Nothing Found
   }
}
Ussaid Iqbal
  • 786
  • 1
  • 7
  • 16