This came as odd to me. From within an Activity class, you can create a context menu through the onCreateContextMenu() and capture those events and process code in the onOptionsItemSelected() method.

Since I was extending an existing View class, it does have its own onCreateContextMenu() but with only one parameter needed with is ContextMenu.

Here is the problem then. There is no onOptionsItemSelected() for the View class but only for Activity.

How then can events of the context menu items be captured? The answer is none that you can just override some method directly.

What I did though, was traversing each MenuItem in the Menu and adding an OnMenuItemClickListener to each one. That did the trick.

Here is a sample code.

By the way, make sure you register your view that will show the context menu by doing this:

So here’s the thing. I wanted my widget to run a task every 12 midnight. The attribute of Intent.ACTION_DATE_CHANGED does not work.

I had read posts in forums that say if you switch back and forth setting the date and time for experimentation to see if the task will run, nothing happens. So the only workaround left is to use an AlarmManager.

Yup, you have to use it rather than being forced to use Intent.ACTION_TIME_TICK which is battery draining as this event will occur every minute.

To set up your AlarmManager to send a broadcast every 12 midnight, do this:

Take note that you have to use getBroadcast() in the PendingIntent class if you want the task in the BroadcastReceiver to be executed. If it is code in a service that you want to run, then call getService().

Okay, this ain’t real. But it looks funny. Good job guys. If you cannot wait to see what is at the end of the clip, scroll over to the last part where the score is almost 999 and you will see a surprising character.

Now, this probably ain’t the reason why the game is scrapped in the App Store and Play Store. But who knows … 😉

Related Posts Plugin for WordPress, Blogger...