0

I have a ListActivity which should call an edit form, much like in the Notepad tutorial. The difference is, that I don't want to call an ACTION_EDIT intent, but the EditorActivity-class directly and also send it the ID. Right now I only can figure out how to directly call the intent

startActivity(new Intent(Intent.ACTION_EDIT,ContentUris.withAppendedId(getIntent().getData(), id)));

or to send an ID with a general request for edit

startActivity(new Intent(getBaseContext(),LocationEditorActivity.class));

So how do I match them together now?

erikbstack
  • 12,878
  • 21
  • 81
  • 115
  • This answer may help you: http://stackoverflow.com/questions/2965109/passing-data-between-activities-in-android/2965248#2965248 – Sergey Glotov Aug 30 '11 at 14:58

2 Answers2

3

Doing this...

startActivity(new Intent(Intent.ACTION_EDIT,ContentUris.withAppendedId(getIntent().getData(), id)));

... is like asking the OS: "hey, I want to you to open an activity that handles this kind of URI and supports the Intent.ACTION_EDIT action".

Then, the choosen activity has to look inside the Uri and extract the ID and process it. So, if you want to launch the activity directly, you just have to explicitly send the ID to that activity:

Intent intent = new Intent(getBaseContext(),LocationEditorActivity.class);
intent.putExtra("the_id", id);
startActivity(intent);

Then, inside the activity, instead of looking for the ID inside the Uri data, you get it from the extras:

long theId = getIntent().getExtras().getLong("the_id", -1);
Cristian
  • 198,401
  • 62
  • 356
  • 264
2

? try to build intent like this:

Intent intent = new Intent(getApplicationContext(), LocationEditor.class);
intent.putExtra("Id", id);
startActivity(intent);

in the recieving Activity:

Intent intent = getIntent();
int id = intent.getExtras().getInt("Id");
Rafael T
  • 15,401
  • 15
  • 83
  • 144