Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting android.intent.action.TIME_SET twice when manually change time

I have a BroadcastReceiver which watches android.intent.action.BOOT_COMPLETED, android.intent.action.TIME_SET and android.intent.action.TIMEZONE_CHANGED.

<receiver android:name="SystemBroadcastReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.TIME_SET" />
            <action android:name="android.intent.action.TIMEZONE_CHANGED" />
            <category android:name="android.intent.category.HOME" />
        </intent-filter>
</receiver>

/** not true, see below Whenever one of these actions happens, the receiver will open an activity. All work well except when I change the minute part of the clock, the android.intent.action.TIME_SET will activate twice, which leads to the activity opening twice.
I find it is strange because if I change the hour part of the clock, android.intent.action.TIME_SET will activate only once. */ My test phone is Galaxy Nexus with 4.2.1. Is this a system bug in 4.2.1 or have I done something wrong?

-----------edit by myself------------ Here is some logs that may helps. Whenever I change the minute, the hour or the date, my activity will launch twice.

02-01 21:16:11.781: D/SystemClock(9012): Setting time of day to sec=1359724560
02-01 21:16:00.023: V/AlarmClock(8932): AlarmInitReceiver finished
02-01 21:16:00.031: D/SystemClock(9012): Setting time of day to sec=1359724560

I do't know why I just change the time in the system settings part once, but the system call the setting time twice.

like image 440
Owen Zhao Avatar asked Aug 23 '26 12:08

Owen Zhao


1 Answers

Verified this behavior on my own Nexus.

However, you should not start an Activity from a BroadcastReceiver. I recommend that you use Notifications!

This way it does not matter if you get the Broadcast twice, because the notification will only update, but not duplicate.

like image 107
cwin Avatar answered Aug 26 '26 01:08

cwin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!