Nokia Lumia 920 or Windows Phone black screen and dead
If your windows phone or Nokia Lumia suddenly blank screen or DEAD, don’t throw away! press Volume Down + Power for 10 seconds. It will revived!
Trust me, Nokia phone isn’t easy to die
If your windows phone or Nokia Lumia suddenly blank screen or DEAD, don’t throw away! press Volume Down + Power for 10 seconds. It will revived!
Trust me, Nokia phone isn’t easy to die
I use Nokia Lumia 920 at this example. To lock Nokia lumia network on 3G / 4G only, we can do quick setup by:
1. Go to dial-pad
Type : ##3282 and call
For older version, please type : ##3282#.
Click settings on right-bottom
From this settings, we can set network running on 2G only, 3G only or even 4G only (LTE).
Here is the steps:
Continue reading
When you got error that your Android application can’t do XMLRPC client to host like 127.0.0.1 or localhost or some IP address like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 01-16 03:45:06.650: W/System.err(7414): org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.1.4:8000 refused 01-16 03:45:06.660: W/System.err(7414): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:178) 01-16 03:45:06.660: W/System.err(7414): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 01-16 03:45:06.660: W/System.err(7414): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) 01-16 03:45:06.660: W/System.err(7414): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359) 01-16 03:45:06.660: W/System.err(7414): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 01-16 03:45:06.660: W/System.err(7414): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 01-16 03:45:06.660: W/System.err(7414): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 01-16 03:45:06.660: W/System.err(7414): at org.xmlrpc.android.XMLRPCClient.callEx(XMLRPCClient.java:178) 01-16 03:45:06.660: W/System.err(7414): at org.xmlrpc.android.XMLRPCClient.call(XMLRPCClient.java:281) 01-16 03:45:06.660: W/System.err(7414): at zin.my.rashidi.android.demo.xmlrpc.LoginActivity$1.onClick(LoginActivity.java:43) 01-16 03:45:06.670: W/System.err(7414): at android.view.View.performClick(View.java:2485) 01-16 03:45:06.670: W/System.err(7414): at android.view.View$PerformClick.run(View.java:9080) 01-16 03:45:06.670: W/System.err(7414): at android.os.Handler.handleCallback(Handler.java:587) 01-16 03:45:06.670: W/System.err(7414): at android.os.Handler.dispatchMessage(Handler.java:92) 01-16 03:45:06.670: W/System.err(7414): at android.os.Looper.loop(Looper.java:130) 01-16 03:45:06.670: W/System.err(7414): at android.app.ActivityThread.main(ActivityThread.java:3687) 01-16 03:45:06.670: W/System.err(7414): at java.lang.reflect.Method.invokeNative(Native Method) 01-16 03:45:06.670: W/System.err(7414): at java.lang.reflect.Method.invoke(Method.java:507) 01-16 03:45:06.670: W/System.err(7414): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 01-16 03:45:06.670: W/System.err(7414): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) 01-16 03:45:06.670: W/System.err(7414): at dalvik.system.NativeStart.main(Native Method) 01-16 03:45:06.680: W/System.err(7414): Caused by: java.net.ConnectException: /192.168.1.4:8000 - Connection refused 01-16 03:45:06.690: W/System.err(7414): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:207) 01-16 03:45:06.690: W/System.err(7414): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437) 01-16 03:45:06.690: W/System.err(7414): at java.net.Socket.connect(Socket.java:1002) 01-16 03:45:06.690: W/System.err(7414): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119) 01-16 03:45:06.690: W/System.err(7414): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143) 01-16 03:45:06.690: W/System.err(7414): ... 20 more 01-16 03:45:06.700: W/System.err(7414): org.xmlrpc.android.XMLRPCException: org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.1.4:8000 refused 01-16 03:45:06.700: W/System.err(7414): at org.xmlrpc.android.XMLRPCClient.callEx(XMLRPCClient.java:237) 01-16 03:45:06.700: W/System.err(7414): at org.xmlrpc.android.XMLRPCClient.call(XMLRPCClient.java:281) 01-16 03:45:06.700: W/System.err(7414): at |
If we got this errors :
1 | Android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 |
What we want?
We want to create a new records and read it.
Problem?
Data is created but we can’t read the new saved records.
Solution? using “moveToFirst()”. Here is the example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | public Cursor createNewRecord() { // Set the new records ID long insertId = database.insert(dbHelper.TABLE_TRACKER, null, values); // Inserting a new records mCursor = database.query(dbHelper.TABLE_TRACKER, allColumns, dbHelper.COLUMN_ID + " = " + insertId, null, null, null, null); mCursor.moveToFirst(); // This will read the NEW RECORD DATA // Mapping cursor data into newData UserDatabase newData = cursorToUser(mCursor); // Close cursor connection mCursor.close(); return newData; } /** * Mapping cursor into UserDatabase handler * @param cursor * @return */ private UserDatabase cursorToUser(Cursor cursor) { UserDatabase userDatabase = new UserDatabase(); userDatabase.setId(cursor.getLong(0)); userDatabase.setDay(cursor.getInt(1)); userDatabase.setIsExercise(cursor.getInt(2)); return userDatabase; } |
When creating a data, sometimes we need to check whether there is a previous data that can be updated or not. To check if data is exists or not, we can use “cursor.moveToFirst()” instead of “cursor.getCount() > 0″. Simple example :
1 2 3 4 5 6 7 8 9 | // Check if days is exists mCursor = database.query(dbHelper.TABLE_TRACKER, allColumns, dbHelper.COLUMN_DAY + "=?", new String[] {Integer.toString(day)}, null, null, null, null); // If data exists, then update the records if(mCursor.moveToFirst()) { // Do your update logic here } |
But, then we can do enhancement like if data exists, then update the data. Meanwhile, if there no records, then create a new records. Here is the implementation :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | Cursor mCursor; // Check if days is exists mCursor = database.query(dbHelper.TABLE_TRACKER, allColumns, dbHelper.COLUMN_DAY + "=?", new String[] {Integer.toString(day)}, null, null, null, null); // If data exists, then update the records if(mCursor.moveToFirst()) { database.update(dbHelper.TABLE_TRACKER, values, dbHelper.COLUMN_ID + "=?", new String[] {String.valueOf(mCursor.getColumnIndex("id"))} ); } else { // Set the new records ID long insertId = database.insert(dbHelper.TABLE_TRACKER, null, values); // Inserting a new records mCursor = database.query(dbHelper.TABLE_TRACKER, allColumns, dbHelper.COLUMN_ID + " = " + insertId, null, null, null, null); mCursor.moveToFirst(); // To get the records } ... mCursor.close() |
After working with the Dialog and Toast, now in the part 3, BodySlap application (which the previous name is Calendar app) now support for taking photos after workout!
The details update and lesson I’ve learned :
1. Intent is a great way to make UI faster and organize the action between activity.
2. Taking picture from Camera and create a storage album for saving the picture
3. Create a listener and attach them into property like Button, Dialog will make code easy to read
Here is the results:
You can grab this on my github : https://github.com/yodiaditya/android
Previous version :
http://www.yodi.biz/2012/12/16/immediate-update-item-cells-in-gridview-android/
http://www.yodi.biz/2012/12/09/build-calendar-applications-with-todo-list-and-activity-in-android-part-2/
http://www.yodi.biz/2012/12/08/build-calendar-applications-with-todo-list-and-activity-in-android-part-1/
Date() in java.utils provide Date instance which contains the date of today. We can showing the day, month, year of today from Date() instance using SimpleDateFormat(
Example:
1 | String today = new SimpleDateFormat("yyyyMMdd_HH:mm:ss").format(new Date()); |
Simple!
To convert Integer into String in Java, we can use toString() method in Integer class instance :
1 2 | Integer hello = 1; String convert = Integer.toString(hello); |
Then, to convert String into Integer, we can use parseInt() method in Integer class instance:
1 2 | String hello = "1"; Integer convert = Integer.parseInt(hello); |
Easy!
Dialog is the good way to providing floating menu in Android which users can do several actions on there. It’s different with Toast which is have purpose for showing information only. At this example, we can try which showing selection menu in Dialog box.
For instance, We will make Users can click Button and Dialog will be pop-up. Suppose we have activity like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public class MainActivity extends Activity { private static final int DIALOG_ALERT = 10; private static final String ANDROID_TAG = "ANDROID"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Button workout = (Button) findViewById(R.id.top_done_button); workout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showDialog(DIALOG_ALERT); } }); } |
showDialog() is built-in method which will showing Dialog based on the unique ID. Later, we can give related Dialog based on ID using switch(). But we should know that showDialog will be expecting for onCreateDialog() method to process all showDialog() request.
Continue reading
We can update immediately background color in items cells (on visibile view) by calling invalidateViews() after do the update. Here is the implementation :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | // Set image adapter instance from private variable imageAdapter = new ItemAdapter(this); // Bind Gridview with calendar XML and set the Adapter final GridView gridView = (GridView) findViewById(R.id.calendar); gridView.setAdapter(imageAdapter); Button workout = (Button) findViewById(R.id.top_done_button); workout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Context context = getApplicationContext(); String text = "Yeah! You're ready workout now!"; Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.show(); // Set date pickers cells imageAdapter.setDatePicker(today.getDate()); gridView.invalidateViews(); } }); |
invalidateViews() called after we doing update on Gridviews items on setDatePicker() method.
Here is the result (without scrolling to update the views) :
And, after I click the workout button:
Next update:
http://www.yodi.biz/2012/12/22/bodyslap-fitness-and-workout-tracker-android-application-part-3/