简体   繁体   English

如何创建这个意图 putExtra?

[英]How to create this intent putExtra?

I am tryng to set a alarm by a id of row in the database.我正在尝试通过数据库中的行 ID 设置警报。 Here is my code to set the inent extra but it gives me a errror at putExtra.这是我设置 inent extra 的代码,但它给了我 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.这是我的 Cursor 从我的数据库中获取 Id。

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

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

putExtra() takes the name (a string) and the actual value as inputs. putExtra()将名称(字符串)和实际值作为输入。

I doubt helper.getById(id) in i.putExtra(helper.getById(id), (long)taskId);我怀疑helper.getById(id) 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 & name -> 额外数据的名称,带有 package 前缀 &
  • value -> The Bundle data value. value -> Bundle 数据值。

Returns:回报:

  • Returns the same Intent object, for chaining multiple calls into a single statement.返回相同的 Intent object,用于将多个调用链接到单个语句中。

Check this link检查此链接

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

Hope I was able to help.希望我能提供帮助。

You can't put a cursor in an intent.您不能将 cursor 放入意图中。 You should read the cursor and make an own datatype of it which you can pass using intents.您应该阅读 cursor 并为其创建自己的数据类型,您可以使用意图传递它。

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

This makes no sense either.这也没有任何意义。 I assume your cursor is the actually data?我假设您的 cursor 是实际数据? In that case the helper.getById() should be the second parameter and taskId the first parameter.在这种情况下, helper.getById() 应该是第二个参数,而 taskId 应该是第一个参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM