diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6dc1094..304827f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,6 +34,10 @@ android:name=".ui.activities.SearchUserActivity" android:label="@string/activity_searchuser_title"/> + + + \ No newline at end of file diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/services/NotificationsService.java b/app/src/main/java/org/communiquons/android/comunic/client/data/services/NotificationsService.java new file mode 100644 index 0000000..5f25119 --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/services/NotificationsService.java @@ -0,0 +1,72 @@ +package org.communiquons.android.comunic.client.data.services; + +import android.app.IntentService; +import android.content.Intent; +import android.support.annotation.Nullable; +import android.util.Log; + +/** + * Notifications service + * + * @author Pierre HUBERT + * Created by pierre on 4/9/18. + */ + +public class NotificationsService extends IntentService { + + /** + * Debug tag + */ + private static final String TAG = "NotificationsService"; + + /** + * Keep run status + */ + private boolean run; + + /** + * Public constructor + */ + public NotificationsService(){ + super("NotificationsService"); + } + + /** + * The IntentService calls this method from the default worker thread with + * the intent that started the service. When this method returns, IntentService + * stops the service, as appropriate. + */ + @Override + protected void onHandleIntent(@Nullable Intent intent) { + + Log.v(TAG, "Start service"); + + while(run){ + + try { + //Make a pause + Thread.sleep(2000); + } catch (InterruptedException e){ + Thread.currentThread().interrupt(); + } + + Log.v(TAG, "Hey there, service !"); + + } + + Log.v(TAG, "Stop service"); + + } + + @Override + public void onCreate() { + super.onCreate(); + this.run = true; + } + + @Override + public void onDestroy() { + super.onDestroy(); + this.run = false; + } +} diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java index 7f3ca41..df19a2a 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java @@ -24,6 +24,7 @@ import org.communiquons.android.comunic.client.data.DatabaseHelper; import org.communiquons.android.comunic.client.data.UsersInfo.GetUsersHelper; import org.communiquons.android.comunic.client.data.conversations.ConversationsListHelper; import org.communiquons.android.comunic.client.data.friendsList.FriendRefreshLoopRunnable; +import org.communiquons.android.comunic.client.data.services.NotificationsService; import org.communiquons.android.comunic.client.data.utils.UiUtils; import org.communiquons.android.comunic.client.ui.fragments.ConversationFragment; import org.communiquons.android.comunic.client.ui.fragments.ConversationsListFragment; @@ -132,6 +133,10 @@ public class MainActivity extends AppCompatActivity friendsListRefreshThread = new Thread( new FriendRefreshLoopRunnable(getApplicationContext(), dbHelper)); friendsListRefreshThread.start(); + + //Start notification thread + Intent intent = new Intent(this, NotificationsService.class); + startService(intent); } @Override