Monday, February 18, 2013

Solution: Invalid payload item type onMenuItemSelected

If you're developing for Android 2.3 or lower, users can reveal the options menu panel by pressing the Menu button.
On Android 3.0 and higher, items from the options menu are presented by the action bar as a combination of on-screen action items and overflow options. Beginning with Android 3.0, the Menu button is deprecated.

You have a sample code in 2.3, which is working fine for MENU option.

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.sample, menu);
        return true;
    }
   
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case R.id.logout:
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }


But there is a following exception when you have run same code in 4.0+ version

java.lang.IllegalArgumentException: Invalid payload item type
at android.util.EventLog.writeEvent(Native Method)
at android.app.Activity.onMenuItemSelected(Activity.java:2565)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:973)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:309)
at android.widget.AdapterView.performItemClick(AdapterView.java:292)
at android.widget.AbsListView.performItemClick(AbsListView.java:1099)
at android.widget.ListView.performItemClick(ListView.java:4758)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2556)
at android.widget.AbsListView$1.run(AbsListView.java:3223)
at android.os.Handler.handleCallback(Handler.java:608)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:4987)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)

Solution: 
Override onMenuItemSelected, and use return true or false than super.onMenuItemSelected(featureId, item).

Wednesday, February 6, 2013

Mac: Change root password without old password


If you don’t have access to an administrator already, you need to acquire root access.

If you don’t have admin access, boot the computer into Single-User Mode by holding CMD+S on startup, mount the drive, and type the command:

Wait until you see a bunch of white writing scrolling by on a black screen. You can release the keys, and you are now in Single-User mode. The computer is ready to continue when you see localhost:/ root# or something similar as the very last line on the screen.

Then follow the steps to reset admin password without old password
 /sbin/fsck -fy
        This command is a 'File System Consistency Check' and works very much the same way as Disk Utility's 'Repair Disk' function.
  /sbin/mount -uw /
        The mount command gives us access to the files on the system so we can make changes.
   
 launchctl load /System/Library/LaunchDaemons/com.apple.opendirectoryd.plist

 and finally:
 passwd
        Then, enter your new root password when prompted twice. After the password has been reset, type:
       
 reboot
        this command restarts the computer.

Friday, January 25, 2013

Android: Solution to catch that the Home button was pressed

Home Button is like an emergency escape button.
Pressing Home twice will always take a user back to the center panel of the Home Screen, so whatever application they're running, it's easy for a user to get back to somewhere they know. You shouldn't really be overriding this unless you're producing a full Home replacement.

Don't  permanently override the Home button without the user confirming it.

We need to do follow three steps here...
1. Override onKeyDown and compare keycode with KeyEvent.KEYCODE_HOME
2. Override onAttachedToWindow()
3. add category to the activity because
CATEGORY_HOME : This is the home activity, that is the first activity that is displayed when the device boots.
<category android:name="android.intent.category.HOME"/>

Solution:  Source Code Here