/** * Adds an entry to the receiver’s dispatch table with an observer using strong reference. */ public synchronized ApptentiveNotificationCenter addObserver(String notification, ApptentiveNotificationObserver observer) { addObserver(notification, observer, false); return this; }
private void registerNotifications() { ApptentiveNotificationCenter.defaultCenter() .addObserver(NOTIFICATION_ACTIVITY_STARTED, this) .addObserver(NOTIFICATION_ACTIVITY_RESUMED, this) .addObserver(NOTIFICATION_APP_ENTERED_FOREGROUND, this) .addObserver(NOTIFICATION_APP_ENTERED_BACKGROUND, this) .addObserver(NOTIFICATION_PAYLOAD_WILL_START_SEND, this) .addObserver(NOTIFICATION_PAYLOAD_DID_FINISH_SEND, this); }
private void registerNotifications() { ApptentiveNotificationCenter.defaultCenter() .addObserver(NOTIFICATION_CONVERSATION_DATA_DID_CHANGE, this) .addObserver(NOTIFICATION_CONVERSATION_STATE_DID_CHANGE, this) .addObserver(NOTIFICATION_MESSAGE_STORE_DID_CHANGE, this); }
protected void registerNotifications() { ApptentiveNotificationCenter.defaultCenter() .addObserver(NOTIFICATION_INTERACTIONS_SHOULD_DISMISS, this) .addObserver(NOTIFICATION_CONVERSATION_STATE_DID_CHANGE, this); }
public ApptentiveTaskManager(Context context, ApptentiveHttpClient apptentiveHttpClient, EncryptionKey encryptionKey) { dbHelper = new ApptentiveDatabaseHelper(context, encryptionKey); /* When a new database task is submitted, the executor has the following behaviors: * 1. If the thread pool has no thread yet, it creates a single worker thread. * 2. If the single worker thread is running with tasks, it queues tasks. * 3. If the queue is full, the task will be rejected and run on caller thread. * */ singleThreadExecutor = new ThreadPoolExecutor(1, 1, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new ThreadPoolExecutor.CallerRunsPolicy()); // If no new task arrives in 30 seconds, the worker thread terminates; otherwise it will be reused singleThreadExecutor.allowCoreThreadTimeOut(true); // Create payload sender object with a custom 'retry' policy payloadSender = new PayloadSender(apptentiveHttpClient, new HttpRequestRetryPolicyDefault() { @Override public boolean shouldRetryRequest(int responseCode, int retryAttempt) { return false; // don't use built-in retry logic for payloads since payload sender listener // would handle it properly } }); payloadSender.setListener(this); ApptentiveNotificationCenter.defaultCenter() .addObserver(NOTIFICATION_CONVERSATION_STATE_DID_CHANGE, this) .addObserver(NOTIFICATION_APP_ENTERED_BACKGROUND, this) .addObserver(NOTIFICATION_APP_ENTERED_FOREGROUND, this); }
.addObserver(NOTIFICATION_APP_ENTERED_FOREGROUND, new ApptentiveNotificationObserver() { @Override public void onReceiveNotification(ApptentiveNotification notification) { .addObserver(NOTIFICATION_APP_ENTERED_BACKGROUND, new ApptentiveNotificationObserver() { @Override public void onReceiveNotification(ApptentiveNotification notification) {
private ApptentiveInternal(Application application, String apptentiveKey, String apptentiveSignature, String serverUrl, boolean shouldEncryptStorage) { if (StringUtils.isNullOrEmpty(apptentiveKey)) { throw new IllegalArgumentException("Apptentive Key is null or empty"); } if (StringUtils.isNullOrEmpty(apptentiveSignature)) { throw new IllegalArgumentException("Apptentive Signature is null or empty"); } this.apptentiveKey = apptentiveKey; this.apptentiveSignature = apptentiveSignature; this.serverUrl = serverUrl; SecurityManager.init(application.getApplicationContext(), shouldEncryptStorage); appContext = application.getApplicationContext(); globalSharedPrefs = application.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE); apptentiveHttpClient = new ApptentiveHttpClient(apptentiveKey, apptentiveSignature, getEndpointBase(globalSharedPrefs)); conversationManager = new ConversationManager(appContext, Util.getInternalDir(appContext, CONVERSATIONS_DIR, true), SecurityManager.getMasterKey()); appRelease = AppReleaseManager.generateCurrentAppRelease(application, this); taskManager = new ApptentiveTaskManager(appContext, apptentiveHttpClient, SecurityManager.getMasterKey()); ApptentiveNotificationCenter.defaultCenter() .addObserver(NOTIFICATION_CONVERSATION_STATE_DID_CHANGE, this) .addObserver(NOTIFICATION_CONVERSATION_WILL_LOGOUT, this) .addObserver(NOTIFICATION_AUTHENTICATION_FAILED, this) .addObserver(NOTIFICATION_INTERACTION_MANIFEST_FETCHED, this) .addObserver(NOTIFICATION_APP_ENTERED_FOREGROUND, this) .addObserver(NOTIFICATION_APP_ENTERED_BACKGROUND, this) .addObserver(NOTIFICATION_CONFIGURATION_FETCH_DID_FINISH, this); }
Observer o4 = new Observer("observer4"); notificationCenter.addObserver("notification1", o1, WEAK_REFERENCE); notificationCenter.addObserver("notification1", o2, STRONG_REFERENCE); notificationCenter.addObserver("notification2", o3, WEAK_REFERENCE); notificationCenter.addObserver("notification2", o4, STRONG_REFERENCE); notificationCenter.addObserver("notification1", o1, WEAK_REFERENCE); notificationCenter.addObserver("notification1", o2, STRONG_REFERENCE); notificationCenter.addObserver("notification2", o3, WEAK_REFERENCE); notificationCenter.addObserver("notification2", o4, STRONG_REFERENCE);