I want to receive time tick in a widget
That is not possible in a reliable fashion.
and tried the code in this link
That code is completely unreliable, as I noted in a comment on the blog post.
it works great on my kindle fire which runs a custom ROM of Android API level 15
You have not run your app for long enough. It will fail on your Kindle Fire as well.
but sometimes the time is wrong on my phone which runs Android 4.2 API level 17
It is possible that Android 4.2 is more aggressive about terminating processes with no active components, which is why it is failing faster for you on your phone. However, it is guaranteed to fail, for the reason I outlined in my comment on the blog post and that you quoted in your question.
Android apps run as OS processes, as programs do in most modern operating systems. Android will terminate processes as needed to reclaim RAM to use for other processes. Android will eventually terminate the process for your app, at which time your registered receiver evaporates.
In the meantime, if onUpdate()
gets called multiple times, you will register multiple receivers for the broadcast, each additional receiver adding that much more overhead.