Return to key-value service Key Value service
1: package com.voipplus.mmsclient.serviceLocalStorage;
2:
3: import android.app.Service;
4: import android.content. ;
5: import android.os.Binder;
6: import android.os.IBinder;
7: import android.util.Log;
8:
9: import androidx.annotation.Nullable;
10:
11: import java.util.HashMap;
12: import java.util.Map;
13: import java.util.Set;
14:
15: public class KeyValueService extends Service {
16:
17: private static final String TAG = "KeyValueService";
18: private final Map<String, String> storage;
19:
20: public class LocalBinder extends Binder {
21: public KeyValueService getService() {
22: return KeyValueService.this;
23: }
24: }
25:
26: private final IBinder binder = new LocalBinder();
27:
28: public KeyValueService() {
29: storage = new HashMap<>();
30: }
31:
32: @Override
33: public void onCreate() {
34: super.onCreate();
35: Log.d(TAG, "KeyValueService created");
36: }
37:
38: @Nullable
39: @Override
40: public IBinder onBind( intent) {
41: Log.d(TAG, "KeyValueService bound");
42: return binder;
43: }
44:
45: @Override
46: public int onStartCommand( intent, int flags, int startId) {
47: Log.d(TAG, "KeyValueService started");
48: return START_STICKY;
49: }
50:
51: public void put(String key, String value) {
52: Log.d(TAG, "Putting key: " + key + ", value: " + value);
53: storage.put(key, value);
54: }
55:
56: public String get(String key) {
57: Log.d(TAG, "Getting key: " + key);
58: return storage.get(key);
59: }
60:
61: public void remove(String key) {
62: Log.d(TAG, "Removing key: " + key);
63: storage.remove(key);
64: }
65:
66: public boolean contains(String key) {
67: Log.d(TAG, "Checking if contains key: " + key);
68: return storage.containsKey(key);
69: }
70:
71: public Set<String> list() {
72: Log.d(TAG, "Listing keys");
73: return storage.keySet();
74: }
75: }
76:
Return to key-value service
AndroidMosaic context:
- 2025 year: Resolve class conflicts #AndroidMosaic
- 2025 year: Application level parameters in configuration #AndroidMosaic
- 2025 year: Create test with junit and pass or dismiss test before application launch #AndroidMosaic
- 2025 year: Ask special permission and listen answer #AndroidMosaic
- 2025 year: Service lifecycle #AndroidMosaic
- 2025 year: AtomicInteger and accept service callback in UI thread, stop progressBar that was run in UiThread #AndroidMosaic
- 2025 year: Generate random data and pass it to RecyclerView with Adapter #AndroidMosaic
- 2025 year: Pass data to new form with Intent and getParcelableExtra #AndroidMosaic
- 2025 year: Access to Contact list #AndroidMosaic
- 2025 year: Using Query and Cursor to read data sequence and fill DataAdapter for RecyclerView #AndroidMosaic
- 2025 year: Custom TabSwithcer #AndroidMosaic
- 2025 year: Custom Dropdownlist with default value based on Spinner #AndroidMosaic
- 2025 year: Create MMS service and route MMS to Emulator #AndroidMosaic
- 2025 year: Vector drawable - fastest way to create icons #AndroidMosaic
- 2025 year: Technique to create Button with own rectangle shape #AndroidMosaic
- 2025 year: Simple HTTP service #AndroidMosaic
- 2025 year: Simple key-value service with Local Storage #AndroidMosaic
- 2025 year: Cryptographic local storage key-value service #AndroidMosaic
- 2025 year: WebRTC service #AndroidMosaic
- 2025 year: SIP service #AndroidMosaic
- 2025 year: Global objects with references to all application services #AndroidMosaic
Comments (
)

Link to this page:
http://www.vb-net.com/AndroidMosaic/KeyValueService.htm
|