mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-30 17:26:36 +00:00
Create notifications service
This commit is contained in:
parent
32eed6322f
commit
939f24937a
@ -34,6 +34,10 @@
|
|||||||
android:name=".ui.activities.SearchUserActivity"
|
android:name=".ui.activities.SearchUserActivity"
|
||||||
android:label="@string/activity_searchuser_title"/>
|
android:label="@string/activity_searchuser_title"/>
|
||||||
|
|
||||||
|
<!-- Notifications background refresh service -->
|
||||||
|
<service android:name=".data.services.NotificationsService"
|
||||||
|
android:exported="false"/>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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.UsersInfo.GetUsersHelper;
|
||||||
import org.communiquons.android.comunic.client.data.conversations.ConversationsListHelper;
|
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.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.data.utils.UiUtils;
|
||||||
import org.communiquons.android.comunic.client.ui.fragments.ConversationFragment;
|
import org.communiquons.android.comunic.client.ui.fragments.ConversationFragment;
|
||||||
import org.communiquons.android.comunic.client.ui.fragments.ConversationsListFragment;
|
import org.communiquons.android.comunic.client.ui.fragments.ConversationsListFragment;
|
||||||
@ -132,6 +133,10 @@ public class MainActivity extends AppCompatActivity
|
|||||||
friendsListRefreshThread = new Thread(
|
friendsListRefreshThread = new Thread(
|
||||||
new FriendRefreshLoopRunnable(getApplicationContext(), dbHelper));
|
new FriendRefreshLoopRunnable(getApplicationContext(), dbHelper));
|
||||||
friendsListRefreshThread.start();
|
friendsListRefreshThread.start();
|
||||||
|
|
||||||
|
//Start notification thread
|
||||||
|
Intent intent = new Intent(this, NotificationsService.class);
|
||||||
|
startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user