yoshi24
yoshi24

Reputation: 3177

How to create this intent putExtra?

I am tryng to set a alarm by a id of row in the database. Here is my code to set the inent extra but it gives me a errror at putExtra.

public void setReminder(long taskId, Calendar when){
    Intent i = new Intent(mContext, OnAlarmReceiver.class);
    i.putExtra(helper.getById(id), (long)taskId);
}

Here is my Cursor fetching the Id from my database.

}
public Cursor getById(String id){
    String [] args = {id};

    return(getReadableDatabase()
        .rawQuery("SELECT _id, title, descrip, taskdatetime, type FROM tasks  WHERE _id = ?", args));
        }

Upvotes: 0

Views: 1477

Answers (2)

Andrew Anderson
Andrew Anderson

Reputation: 457

putExtra() takes the name (a string) and the actual value as inputs.

I doubt helper.getById(id) in i.putExtra(helper.getById(id), (long)taskId); returns a string.

Check that.

public Intent putExtra (String name, Bundle value)

Parameters:

  • name -> The name of the extra data, with package prefix &
  • value -> The Bundle data value.

Returns:

  • Returns the same Intent object, for chaining multiple calls into a single statement.

Check this link

http://developer.android.com/reference/android/content/Intent.html#putExtra%28java.lang.String,%20android.os.Bundle%29

Hope I was able to help.

Upvotes: 2

matsjoe
matsjoe

Reputation: 1480

You can't put a cursor in an intent. You should read the cursor and make an own datatype of it which you can pass using intents.

   i.putExtra(helper.getById(id), (long)taskId);

This makes no sense either. I assume your cursor is the actually data? In that case the helper.getById() should be the second parameter and taskId the first parameter.

Upvotes: 1

Related Questions