(2nd ed.): Item 1! “A second advantage of static factory methods is that, unlike constructors, they are not required to create a new object each time they’re invoked.”
E/AndroidRuntime( 1245): Process: se.hellsoft.apptl.app, PID: 1245 E/AndroidRuntime( 1245): java.lang.RuntimeException: An error occured while executing doInBackground() E/AndroidRuntime( 1245): at android.os.AsyncTask$3.done(AsyncTask.java:300) E/AndroidRuntime( 1245): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355) E/AndroidRuntime( 1245): at java.util.concurrent.FutureTask.setException(FutureTask.java:222) E/AndroidRuntime( 1245): at java.util.concurrent.FutureTask.run(FutureTask.java:242) E/AndroidRuntime( 1245): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) E/AndroidRuntime( 1245): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) E/AndroidRuntime( 1245): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) E/AndroidRuntime( 1245): at java.lang.Thread.run(Thread.java:841) E/AndroidRuntime( 1245): Caused by: java.lang.IllegalStateException: Fragment FirstFragment{52836468} not attached to Activity E/AndroidRuntime( 1245): at android.support.v4.app.Fragment.getResources(Fragment.java:601) E/AndroidRuntime( 1245): at se.hellsoft.apptl.app.MainActivity$FirstFragment $1.doInBackground(MainActivity.java:115) E/AndroidRuntime( 1245): at se.hellsoft.apptl.app.MainActivity$FirstFragment $1.doInBackground(MainActivity.java:109) E/AndroidRuntime( 1245): at android.os.AsyncTask$2.call(AsyncTask.java:288) E/AndroidRuntime( 1245): at java.util.concurrent.FutureTask.run(FutureTask.java:237) E/AndroidRuntime( 1245): ... 4 more
action string and data Uri! ! •onBind() and onUnbind() only called once per unique Intent •START_STICKY will give a null Intent when Service is restarted by the system •Binder calls run on local thread for process-local service
uri, ContentValues[] values) { SQLiteDatabase db = mDatabaseHelper.getWritableDatabase(); int match = sUriMatcher.match(uri); int inserted = 0; switch (match) { case TASKS_CODE: try { db.beginTransaction(); for (ContentValues value : values) { long id = db.insert(Contract.TABLE_NAME, "", value); if (id <= 0) throw new SQLException("Failed with inserting."); inserted++; } db.setTransactionSuccessful(); getContext().getContentResolver().notifyChange(uri, null); } finally { db.endTransaction(); } } return inserted; }