Presence (online status, activity) for collaboration in mobile app

TRUETECH is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
Presence (online status, activity) for collaboration in mobile app
Medium
~3-5 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    757
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1054
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    874
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

Implementing Presence (Online Status, Activity) for Collaboration in Mobile Applications

Presence — ephemeral data layer about what user does right now: online, on which screen, what editing, where cursor. Unlike regular app data, presence doesn't store in DB — lives only while connection active. But correct implementation harder than seems.

Why Can't Just Store is_online in Firestore

Classic mistake: add lastSeen field to user document and update every 30 seconds. Problems:

  • Battery kill: constant write operations in background. Android 8+ limits background tasks, iOS kills Background Fetch in minutes.
  • Wrong status on crash: app crashed — is_online: true stays until next update.
  • Races on multiple devices: user online on phone and tablet. Left tablet — reset status, but phone still active.

Firebase Realtime Database: Correct Implementation via onDisconnect

Firebase RTDB has built-in mechanism — onDisconnect(). Server executes specified operation automatically on connection break, even if client just lost network:

import database from '@react-native-firebase/database';

const userStatusRef = database().ref(`/status/${userId}`);
const isOfflineData = { state: 'offline', lastChanged: database.ServerValue.TIMESTAMP };
const isOnlineData = { state: 'online', lastChanged: database.ServerValue.TIMESTAMP };

// Register disconnect action BEFORE setting online
await userStatusRef.onDisconnect().set(isOfflineData);
await userStatusRef.set(isOnlineData);

database.ServerValue.TIMESTAMP — server timestamp, doesn't depend on device timezone. Important: onDisconnect registered before set(isOnlineData) — otherwise race condition, client may disconnect between two calls.

For multiple device support — counter of active sessions instead of boolean flag:

// Use transaction for atomic increment
const sessionsRef = database().ref(`/sessions/${userId}`);
await sessionsRef.transaction(current => (current || 0) + 1);
await sessionsRef.onDisconnect().transaction(current => Math.max((current || 1) - 1, 0));

is_online = sessions > 0. Crash on one device decrements counter via onDisconnect, doesn't affect other sessions.

AppState: Syncing with iOS/Android Lifecycle

import { AppState, AppStateStatus } from 'react-native';

useEffect(() => {
  const subscription = AppState.addEventListener('change', (nextState: AppStateStatus) => {
    if (nextState === 'active') {
      userStatusRef.onDisconnect().set(isOfflineData);
      userStatusRef.set(isOnlineData);
    } else if (nextState === 'background' || nextState === 'inactive') {
      userStatusRef.set(isOfflineData);
      userStatusRef.onDisconnect().cancel(); // cancel, already did manually
    }
  });
  return () => subscription.remove();
}, []);

On Android on background you have seconds before system freezes JS thread. userStatusRef.set() — async operation, not guaranteed. onDisconnect() as fallback mandatory.

Typed Presence with Additional Context

Beyond online/offline, often need to know what user does:

type PresenceState = {
  status: 'online' | 'idle' | 'offline';
  currentScreen: string | null;
  editingItemId: string | null;
  lastChanged: number;
};

idle — user opened app but 5+ minutes didn't touch screen. Detected via PanResponder or TouchableWithoutFeedback on root component with debounce timer.

Display: Avatars with Indicator

In participants list with presence data add colored badge:

  • Green: status === 'online'
  • Yellow: status === 'idle'
  • Gray: status === 'offline', show lastChanged as "was online N minutes ago"

Nuance: don't update lastChanged on every presence change — only on status change. Otherwise list redraws every seconds for each active user.

Assessment

Firebase RTDB presence with multiple device support, idle-detection and UI component: 1–3 weeks. Custom WebSocket presence on own backend: 2–4 weeks.