Jonas M F Banurea
Jonas M F Banurea

Reputation: 47

Sending parameter values via intent

I want to access the same class according to the number of user requests. I've tried following this tutorial that use putExtra, but it is an example for two different classes, whereas I need intent to call the same class.

here my codes:

   String dataX="dataX";
   int count;
   while(count >0){
       count--;
       startActivity(M_InsertData.this, M_InsertData.class);
       Intent toAlternative = new Intent(M_InsertData.this, M_InsertData.class);
       toAlternative.putExtra(dataX, count);

   }

Upvotes: 0

Views: 126

Answers (1)

matt5784
matt5784

Reputation: 3085

When you call startActivity(M_InsertData.this, M_InsertData.class); what you are really doing is casting those two params into an intent and calling start activity on it. Then you create an intent and add some extra data to it but never use it for anything. Instead, the last three lines in the while loop should read

       Intent toAlternative = new Intent(M_InsertData.this, M_InsertData.class);
       toAlternative.putExtra(dataX, count);
       startActivity(toAlternative);

That should properly pass the extra data (via intent) to the new activity.

Upvotes: 1

Related Questions