Thursday, October 27, 2011

OSX Lion Boot Options

This is a reminder for myself~

Once Mac OSX Lion starts booting up, you may press the following key combinations for analyzing and/or fixing your system:
  • Command + V => Verbose mode, so you can check what makes your system wait or which error makes it stuck.
  • Command + R => Recovery mode, you can access disk utilities to check and/or fix your disk, access the Internet for solution, and reinstall your OSX.
  • Option => You can select which disk to boot
  • Command + S => Single user mode, the system will boot into terminal mode and login as root. You can also try to check and fix your disk here, via commands (fsck, fsck_hfs etc.)
  • C => Boot CD/DVD rom.

Thursday, August 11, 2011

Programming with Windows Screensaver

While developing your Windows application/system, you may want to disable/enable/deactivate the screensaver. Here are some ways to do so: (ref: http://support.microsoft.com/kb/140723)

If the screensaver is activated (because halting for some time) and you want to kill it (activate the machine), you may use the following C code:

To temporally disable screensaver (maybe your application is working on something and you do not want the screen to turn off automatically), you may use:

However, your system may go wrong using the above code. Imagine if your application crashed after disabling the screensaver, then it will keep disabled until you re-enable it manually. In this case, you can just set the state of your current thread to tell the system that this thread requires attention.

Monday, July 4, 2011

Android Kill Self-process

I came across a line of source code written by some others today, and it gives me a behavior I have never thought about. The whole application (simplified version) consists of two activities. A user first launches up the main activity and clicks a button in this activity. This starts the second activity. The user then clicks a button in the second activity, and this line is called:


I thought the whole application will be killed and the system will go back to home screen but it does not. Instead the application goes back to main activity and calls its onCreate() again. I am surprised, and then I did a test. I added finish() in main activity after startActivity(). This time, killing the process just closed the whole application.

I tried to search for the reason of this behavior but I cannot find out the answer. Normally, processes are managed by Android system and one should not handle them himself. I believe this behavior is because some resource is not freed yet when the process is killed, and the system thinks the application should relaunch (or it thinks the application is still launching for the first time?).