diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-03-03 23:33:25 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-11-10 17:40:55 +0100 |
commit | 1e33c4940ea43093a80077fbb7249b013e35a1f1 (patch) | |
tree | c908396564aeca07472c016c9f91faac127c9e71 /Android/06-Notifications/Notifications/src/course/labs/notificationslab/MainActivity.java | |
parent | e55eeb311c01775c123eea7bd2f6e9c82fa067b4 (diff) | |
download | coursera-1e33c4940ea43093a80077fbb7249b013e35a1f1.zip coursera-1e33c4940ea43093a80077fbb7249b013e35a1f1.tar.gz |
Android : 06-Notifications: implement
Diffstat (limited to 'Android/06-Notifications/Notifications/src/course/labs/notificationslab/MainActivity.java')
-rw-r--r-- | Android/06-Notifications/Notifications/src/course/labs/notificationslab/MainActivity.java | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/Android/06-Notifications/Notifications/src/course/labs/notificationslab/MainActivity.java b/Android/06-Notifications/Notifications/src/course/labs/notificationslab/MainActivity.java index eebf924..e74daa9 100644 --- a/Android/06-Notifications/Notifications/src/course/labs/notificationslab/MainActivity.java +++ b/Android/06-Notifications/Notifications/src/course/labs/notificationslab/MainActivity.java @@ -17,6 +17,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.widget.Toast; import android.os.Bundle; import android.util.Log; @@ -70,13 +71,10 @@ public class MainActivity extends Activity implements SelectionListener { log("In ensureData(), mIsFresh:" + mIsFresh); if (!mIsFresh) { - // TODO: - // Show a Toast Notification to inform user that - // the app is "Downloading Tweets from Network" log ("Issuing Toast Message"); + Toast.makeText(MainActivity.this, "Downloading Tweets from Network", Toast.LENGTH_SHORT).show(); - // TODO: - // Start new AsyncTask to download Tweets from network + new DownloaderTask(MainActivity.this).execute(URL_LGAGA, URL_RBLACK, URL_TSWIFT); // Set up a BroadcastReceiver to receive an Intent when download // finishes. @@ -84,10 +82,9 @@ public class MainActivity extends Activity implements SelectionListener { @Override public void onReceive(Context context, Intent intent) { log("BroadcastIntent received in MainActivity"); - // TODO: - // Check to make sure this is an ordered broadcast - // Let sender know that the Intent was received - // by setting result code to RESULT_OK + if (isOrderedBroadcast()) { + setResultCode(RESULT_OK); + } } }; } else { @@ -145,15 +142,16 @@ public class MainActivity extends Activity implements SelectionListener { @Override protected void onResume() { super.onResume(); - // TODO: - // Register the BroadcastReceiver to receive a - // DATA_REFRESHED_ACTION broadcast + if(mRefreshReceiver != null) { + registerReceiver(mRefreshReceiver, new IntentFilter(DATA_REFRESHED_ACTION)); + } } @Override protected void onPause() { - // TODO: - // Unregister the BroadcastReceiver + if(mRefreshReceiver != null) { + unregisterReceiver(mRefreshReceiver); + } super.onPause(); } |