我正在为我的新项目使用android房间持久性库.我想更新一些表的字段.我试过像我一样Dao
-
// Method 1:
@Dao
public interface TourDao {
@Update
int updateTour(Tour tour);
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用此方法进行更新时,它会更新实体中与tour对象的主键值匹配的每个字段.我用过@Query
// Method 2:
@Query("UPDATE Tour SET endAddress = :end_address WHERE id = :tid")
int updateTour(long tid, String end_address);
Run Code Online (Sandbox Code Playgroud)
它正在工作,但在我的案例中会有很多查询,因为我的实体中有很多字段.我想知道如何更新某些字段(不是全部),例如Method 1
id = 1; (id是自动生成主键).
// Entity:
@Entity
public class Tour {
@PrimaryKey(autoGenerate = true)
public long id;
private String startAddress;
private String endAddress;
//constructor, getter and setter
}
Run Code Online (Sandbox Code Playgroud) 我创建了一个Contentprovide并实现了它的update()方法,如下所示:
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
final SQLiteDatabase db = mHelper.getWritableDatabase();
int count = db.update(InslideDB.FOLDER_TABLE, values, selection, selectionArgs);
/* To notify the observer */
this.getContext().getContentResolver().notifyChange(URI, null);
return count;
}
Run Code Online (Sandbox Code Playgroud)
如何在appwidget中收到通知?谢谢!
我正在尝试这个解析器,但没有Log(-------------------- Date Changed)打印:
class DataProviderObserver extends ContentObserver {
private AppWidgetManager mAppWidgetManager;
private ComponentName mComponentName;
DataProviderObserver(AppWidgetManager mgr, ComponentName cn, Handler h) {
super(h);
mAppWidgetManager = mgr;
mComponentName = cn;
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange); //NOTE: Have to call this. dwy.
// …
Run Code Online (Sandbox Code Playgroud) 我每天都会重复闹钟.但它会有几秒或几分钟的错误.我怎样才能让它更准确?
PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), notificationId, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)getActivity().getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 30);
long startUpTime = calendar.getTimeInMillis();
if (System.currentTimeMillis() > startUpTime) {
startUpTime = startUpTime + 24*60*60*1000;
}
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, startUpTime, 24*60*60*1000 , pendingIntent);
Run Code Online (Sandbox Code Playgroud)