Android: Returning Value To The Calling Activity

In my previous post, I had explained how to switch (call) to another activities and passing value to it. This time I will try to explain on how to return some value back to the calling activity. Returning some values to the calling activity can be done by the following example: Intent resultData = new Intent(); String token = “some token”; String verifier = “some verifier”; resultData.putExtra(“token”, token); resultData.putExtra(“verifier”, verifier); setResult(Activity.RESULT_OK, Continue reading

Backup Your MySQL Database Contents to SQL File Using PHP

Here’s a snippet to backup MySQL database content to SQL file using PHP code. This code is very useful when you want to make a daily or hourly snapshot of your currently running database. Or maybe you want to add a backup feature on your blog CMS. backup_tables(‘localhost’,'username’,'password’,'blog’); /* backup the db OR just a table */ function backup_tables($host,$user,$pass,$name,$tables = ‘*’) { $link = mysql_connect($host,$user,$pass); mysql_select_db($name,$link); //get all of the Continue reading

Replace Multiple Backslash Character Using preg_replace() in PHP

It seems like an easy problem to solve, but It’s not as easy as it seems. Assuming I have this string in PHP: \\\super\\\\\\man\\\ and I would like to replace all the backslashes into space or other characters is not as easy as using str_replace() function. The number of backslashes may be 1 or more. But all consecutive need to be replace into ONE space.

File Handling in PHP: Read/Write To And From Text File

As a simple data storage alternative to Database Management System (e.g. MySQL) in PHP we can use plain text file. For example, a plain text file to store page counter information. Below is an example on how to store a simple string (text) into a text (.txt) file: <?php $data = ‘some text’; $fp = fopen(‘counter.txt’, ‘w’); if($fp) { fwrite($fp, $data); fclose($fp); } ?> Assuming a file named counter.txt exists Continue reading

Pemrograman Web: Tugas Pengganti Kuliah – Selasa 5 Maret 2013

Perkuliahan mata kuliah Pemrograman Web untuk kelas SI-A dan SI-B hari Selasa 5 Maret 2013 diberikan tugas pengganti perkuliahan dikarenakan saya selaku dosen pengampu mata kuliah tersebut ada tugas untuk mengajar di Universitas Brawijaya Kediri. Adapun tugas pengganti untuk mata kuliah tersebut hari Selasa 5 Maret 2013 adalah: Carilah sebuah permasalahan dan algoritma yang dapat menyelesaikan permasalahan tersebut (contoh: sort, search, perpangkatan, dll). Daftar pilihannya dapat dilihat di link ini, Continue reading

Tutorial: Android SQLite Database

SQLite is one of several ways that Android provide to store data. SQLite is already come with vanilla Android OS and it is very light weight to be used under mobile environment. Below is the tutorial on how to create classes to handle SQLite database operations. For the sake of simplicity, I only uses one table with only 3 columns to store cars information. The three columns are id (INT), Continue reading

Android: Simple Class For Easy Writing And Reading SharedPreferences String Value

SharedPreferences is used to store small configurations or settings data in your Android application. For example, as username or user preferences data storage. Just like variables, shared preferences can be identified by “key” string as “variable” name. Shared preferences are relatives to application. So it can not be accessed by other application directly. In the following example, I would like to store the username of logged in user so in Continue reading

Thread in Android: An Example

StrictMode is most commonly used to catch accidental disk or network access on the application’s main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications. By keeping your application’s main thread (UI thread) responsive, you also prevent ANR (Application Not Responding) dialogs from being shown to users. Network requests being made on UI thread may Continue reading