Chronometer start from specific value in Notification RemoteViews

有些话、适合烂在心里 提交于 2021-01-28 11:41:11

问题


I'm trying to start the chronometer in a new notification but from a paused(elapsed) "the elapsed time is got from another chronometer", not from zero

The start base in Notification RemoteViews.class of chronometer is different from the start base in Chronometer.class it has different calculations

Notification notification = new 
NotificationCompat.Builder(getApplicationContext())
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setContentTitle(songName).build();
notification.contentView = simpleContentView;

And I get the timeWhenPaused

long timeWhenPaused = myChronometer.getBase() - SystemClock.elapsedRealtime();

Then create the chronometer

notification.contentView.setChronometer(R.id.chronometer_recorder
                            , (SystemClock.elapsedRealtime() + timeWhenPaused)
                            , null
                            , true
                    );

It starts from Zero


回答1:


I tried many method with calculations finally got this.

long elapsedMillis = SystemClock.elapsedRealtime() - myChronometer.getBase();

Then

notification.contentView.setChronometer(R.id.chronometer_recorder_notification
                    ,(SystemClock.elapsedRealtime() - elapsedMillis ^5)
                    ,null
                    ,true
            );


来源:https://stackoverflow.com/questions/47926492/chronometer-start-from-specific-value-in-notification-remoteviews

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!