[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [snowflake-mobile/master] Added onStartCommand to start and stop service
commit 91871788d224ba0b4bb0956b369ea6a1345c893e
Author: Hashik Donthineni <HashikDonthineni@xxxxxxxxx>
Date: Fri Jun 5 03:52:08 2020 +0530
Added onStartCommand to start and stop service
---
.../torproject/snowflake/MyPersistentService.java | 28 ++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
index bdb2e54..5bafada 100644
--- a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
+++ b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
@@ -25,6 +25,24 @@ public class MyPersistentService extends Service {
}
@Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ Log.d(TAG, "onStartCommand: executed with startId: " + startId);
+ sharedPreferences = getSharedPreferences(getString(R.string.sharedpreference_file), MODE_PRIVATE);
+
+ if (intent != null) {
+// if (intent.getAction().equals(ForegroundServiceConstants.ACTION_START))
+// //TODO: Start Service
+// else
+// //TODO: Stop Service
+ } else {
+ Log.d("onStartCommand:", "Null intent detected"); //Intent is null if system restarts the service.
+ }
+
+ //If the service is killed. OS will restart this service if it's START_STICKY.
+ return START_STICKY;
+ }
+
+ @Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "onCreate: Service Created");
@@ -35,6 +53,16 @@ public class MyPersistentService extends Service {
startForeground(ForegroundServiceConstants.DEF_NOTIFICATION_ID, notification);
}
+ @Override
+ public void onDestroy() {
+ Log.d(TAG, "onDestroy: Service Destroyed");
+ sharedPreferencesHelper(ForegroundServiceConstants.SERVICE_STOPPED);
+
+ //TODO: Dispose all connections.
+
+ super.onDestroy();
+ }
+
/**
* Helper function to edit shared preference file.
*
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits