Thursday, December 19, 2013

Xamarin Course on 8-10 Jan 2014 Confirmed!

I am happy to announce that the MOB101 - Xamarin Course on 8-10 Jan 2014 is now confirmed!

Using the Xamarin Studio, you can now create compelling Android and iOS (iPhone and iPad) apps using C#. Best of all, you can share your application logic  between the two platforms. And when you are ready, you can easily port your application to Windows Phone 8 (using Visual Studio)! And did I mention that your app developed will be a native app and a first-class citizen on the platform?

On 8-10 Jan 2014, I will have the 3-day course on using Xamarin to build iOS and Android apps. This course covers both iOS and Android development. As such you need to bring along your own Mac, as the testing needs to be done on the iPhone Simulator, which requires a Mac.

For those of you who want to know about the power of Xamarin, check out my article on the Jan/Feb issue of Code Magazine!


Wednesday, December 18, 2013

The Pebble appstore is coming to a smartphone near you!

The Pebble appstore is coming to a smartphone near you! Arriving in early 2014, you can now download your favourite Pebble apps through the Pebble appstore. 


Now is the time to crank up your development engines and write apps for the Pebble. Join our inaugural Pebble programming course on the follow dates:

* 6-7 Jan 2014 (Mon-Tue)
* 6-7 Feb 2014 (Thu-Fri)
* 10-11 Mar 2014 (Mon-Tue)

See you at the course! All participants will get a Pebble watch worth US$150!

Android Bluetooth Low Energy Programming course on 26 Dec 2013 confirmed!

I am happy to announce that the Android Bluetooth Low Energy Programming course on 26 Dec 2013. You will get a unit of the Ti SensorTag, which allows you to write an Android app to read the various sensors embedded within it. For more details, check out the course outline here.

Tuesday, December 10, 2013

PHP Tip - Redirecting to Another Page


There are times where you need to redirect the user to another page. For example, after the user has successfully registered as a user at your site, you might want to redirect them to the login page. As such, you need to be able to programmatically redirect the user to the target page.

To redirect the user to another page using PHP, you can use the header() function, like this:

<?php   
header('Location: anotherpage.php');   
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">

This snippet of code must be placed at the top of the document, before the DOCTYPE element. The above code will automatically redirect the user to anotherpage.php whenever the user loads it.

However, if you want to programmatically redirect the user based on certain conditions (such as user successfully registering at your site), you have to do a little more work. The following code snippet redirects the user after injecting a delay of five seconds:

//--redirect to another page---
$delay = 5;  //---five seconds---
$redirectPageUrl = "login.php";
header( "Refresh: $delay; url=$redirectPageUrl" );
echo "You will now be redirected to the login page, after $delay seconds.";
exit();

The above snippet of code will redirect the user to the login.php page. Be aware though, that the above snippet must be accompanied by the following snippet, placed at the top of your PHP page:

<?php
ob_start();
?>

The ob_start() function turns the output buffer on so that no HTML code is sent to the client until the entire PHP script has been processed. If you don’t do that, by the time the header() function performs a redirection it would be too late as HTML code has already been sent to the client. 

Sunday, December 08, 2013

PHP and MySQL Course on 19-20 Dec 2013 confirmed!

If you have always wanted to learn web programming, this is your best chance! The PHP and MySQL course on the 19-20 Dec is now confirmed!
You will learn how to write web applications that contains features like online voting and shopping carts.

Android Course on 23-24 Dec 2013 is now confirmed!

For those of you who are considering attending the Foundation of Android Programming course on 23-24 Dec 2013, you would be delighted to know that it is now confirmed! 

We will be covering Android 4.4 and be sure to bring along your own devices for testing!

Android Tip - Saving Instance State

One of the characteristics of an activity that it is automatically destroyed and recreated whenever there is a change in device orientation. As such, it is important that you take note of this so that you don’t lose any data when the user accidentally rotates the device.


When an activity is rotated, the activity will fire the onSaveInstanceState() method before the activity is destroyed:

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);

        //---save whatever you need to persist—
        outState.putString("str", "This is a string!");
    }

You can make use of the Bundle object to save the state of your activity.

Do not confuse the onSaveInstanceState() method with the onPause() and onStop() methods, as:
·       The onPause() and onStop() methods are always called when an activity is sent to the background or is being destroyed
·       When an activity is being destroyed, the onSaveInstanceState() method will not be called; it will however be called when the activity is sent to the background
·       The onSaveInstanceState() method will be called when it is being killed by the OS due to a memory crunch

When the activity is created, you can use the onRestoreInstanceState() method to restore the previous saved state of the activity:  

    @Override
    public void onRestoreInstanceState(
    Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);

        //---retrieve the information persisted earlier---
        String s = savedInstanceState.getString("str");
        Toast.makeText(this, s, Toast.LENGTH_LONG).show();
    }


While usually you can also use the onCreate() method to restore the activity state, the onRestoreInstanceState() method is another method for you to restore the activity state.

Thursday, December 05, 2013

Android Tip - Transferring File via Bluetooth

If you want to easily transfer a file from your application to another Android device, you can make use of Bluetooth.

Beginning with Android 4.1, you can now make use of the built-in Bluetooth Sharing app available on the device. The following code snippet shows how to use an Intent object to manually invoke the Bluetooth Sharing app to send an image from one device to another:

import java.io.File;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;

...

        
        //---assuming you have a file named MyPhoto.jpg in
        // your SD card---
        File file = new File(
            Environment.getExternalStorageDirectory().
            getPath() + "/MyPhoto.jpg");
        Intent i = new
            Intent(android.content.Intent.ACTION_SEND);
        i.setType("image/*");
        i.setComponent(
            new ComponentName("com.android.bluetooth",                         
   "com.android.bluetooth.opp.BluetoothOppLauncherActivity"));
        i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        startActivity(i);      

    }