小编Fer*_*tsu的帖子

Room RxJava Flowable 在插入后不发出更新

我有一项服务,每次找到新位置时都会将数据插入房间数据库。

@Override
public void onLocationUpdate(Location location) {
    final Point point = new Point();
    point.setTripId(0);
    point.setDate(new Date());
    point.setLatitude(location.getLatitude());
    point.setLongitude(location.getLongitude());

    Completable completable = Completable
            .fromAction(() -> appDataBase.pointDao().insert(point));
}
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,当我在主活动中订阅时,我没有在数据库中获取新值,它只返回一个空列表一次:

appDataBase.pointDao().getAllByTripId(0)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(points -> Log.d("TripActivity", points.toString()));
Run Code Online (Sandbox Code Playgroud)

这是我的道:

@Dao
public interface PointDao {
    @Query("SELECT * FROM points WHERE tripId = :tripId")
    Flowable<List<Point>> getAllByTripId(int tripId);

    @Insert
    void insert(Point point);

    @Query("DELETE FROM points WHERE tripId = :tripId")
    void deleteByTripId(int tripId);
}
Run Code Online (Sandbox Code Playgroud)

我的实体:

@Entity(tableName = "points")
public class Point {

    public static final int DEFAULT_TRIP_ID = …
Run Code Online (Sandbox Code Playgroud)

android

3
推荐指数
1
解决办法
2011
查看次数

MediaSession 没有从 MediaStyle Notification 获得任何回调

我创建了一个扩展 MediaBrowserServiceCompat 的服务。该服务持有对我的播放器的引用并创建一个带有回调的新 MediaSession。每次播放器更改状态时,我都会更新 MediaSession 的播放状态并创建一个 MediaStyle 通知。当我开始在播放器中播放某些内容时会显示通知,但通知中的按钮没有触发 MediaSession 回调,它们不执行任何操作。我在 MediaSession 中设置了正确的标志,我将会话设置为活动状态,我在播放状态中设置了正确的操作,我正在将会话令牌传递给通知,但仍然没有从中获得任何回调. 我真的不知道我做错了什么。所有这些代码都在我的应用程序导入的模块中。

我的 NotificationHelper 类:

private final MusicService mService;

private final NotificationCompat.Action mPlayAction;
private final NotificationCompat.Action mPauseAction;
private final NotificationCompat.Action mNextAction;
private final NotificationCompat.Action mPrevAction;
private final NotificationManager mNotificationManager;

public MediaNotificationManager(MusicService service) {
    mService = service;

    mNotificationManager =
            (NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE);

    mPlayAction =
            new NotificationCompat.Action(
                    R.drawable.exo_icon_play,
                    "Play",
                    MediaButtonReceiver.buildMediaButtonPendingIntent(
                            mService,
                            PlaybackStateCompat.ACTION_PLAY));
    mPauseAction =
            new NotificationCompat.Action(
                    R.drawable.exo_icon_pause,
                    "Pause",
                    MediaButtonReceiver.buildMediaButtonPendingIntent(
                            mService,
                            PlaybackStateCompat.ACTION_PAUSE));
    mNextAction =
            new NotificationCompat.Action(
                    R.drawable.exo_icon_next,
                    "Next",
                    MediaButtonReceiver.buildMediaButtonPendingIntent(
                            mService,
                            PlaybackStateCompat.ACTION_SKIP_TO_NEXT));
    mPrevAction = …
Run Code Online (Sandbox Code Playgroud)

android android-notifications android-mediasession mediabrowserservicecompat

3
推荐指数
1
解决办法
2493
查看次数