PHPackages                             djurovicigoor/app-lifecycle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. djurovicigoor/app-lifecycle

ActiveNativephp-plugin

djurovicigoor/app-lifecycle
===========================

App lifecycle state detection plugin for NativePHP Mobile detects foreground/background transitions on Android and iOS.

v1.0.0(2w ago)010↑200%1MITPHPPHP ^8.2

Since Mar 9Pushed 2w agoCompare

[ Source](https://github.com/djurovicigoor/app-lifecycle)[ Packagist](https://packagist.org/packages/djurovicigoor/app-lifecycle)[ RSS](/packages/djurovicigoor-app-lifecycle/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (2)Used By (0)

AppLifecycle Plugin for NativePHP Mobile
========================================

[](#applifecycle-plugin-for-nativephp-mobile)

App lifecycle state detection for NativePHP Mobile — detects foreground/background transitions on Android and iOS.

[![Android](https://camo.githubusercontent.com/98712a85e56c0754be6cf881587c7203378f7824ea33b4b4707b6f5947e7920e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f416e64726f69642d32312532422d3344444338343f6c6f676f3d616e64726f6964266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/98712a85e56c0754be6cf881587c7203378f7824ea33b4b4707b6f5947e7920e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f416e64726f69642d32312532422d3344444338343f6c6f676f3d616e64726f6964266c6f676f436f6c6f723d7768697465)[![iOS](https://camo.githubusercontent.com/c1e8bfa3b0f99a1957daeceb7f8407c0f2eabfe4b0a79c2b5a6084ce6cdb0347/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f694f532d31352e302532422d3030303030303f6c6f676f3d6170706c65266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/c1e8bfa3b0f99a1957daeceb7f8407c0f2eabfe4b0a79c2b5a6084ce6cdb0347/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f694f532d31352e302532422d3030303030303f6c6f676f3d6170706c65266c6f676f436f6c6f723d7768697465)[![License](https://camo.githubusercontent.com/b8cadaa967891081f8f165695470689986c028821dd8a040132f6e661795dc0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c7565)](https://camo.githubusercontent.com/b8cadaa967891081f8f165695470689986c028821dd8a040132f6e661795dc0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c7565)

---

Installation
------------

[](#installation)

```
composer require djurovicigoor/app-lifecycle
```

Plugin Registration
-------------------

[](#plugin-registration)

Register the plugin in your `NativeServiceProvider`:

```
// app/Providers/NativeServiceProvider.php

public function plugins(): array
{
    return [
        // ...other plugins
        \Djurovicigoor\AppLifecycle\AppLifecycleServiceProvider::class,
    ];
}
```

---

Usage
-----

[](#usage)

### PHP — Laravel Event Listener

[](#php--laravel-event-listener)

Register a listener in your `AppServiceProvider`:

```
// app/Providers/AppServiceProvider.php

use Djurovicigoor\AppLifecycle\Events\AppForegrounded;
use Djurovicigoor\AppLifecycle\Events\AppBackgrounded;
use Illuminate\Support\Facades\Event;

public function boot(): void
{
    // Fires every time the user returns to the app
    Event::listen(AppForegrounded::class, function (AppForegrounded $event) {
        // make an API call, refresh data, etc.
    });

    // Fires every time the user leaves the app
    Event::listen(AppBackgrounded::class, function (AppBackgrounded $event) {
        // flush pending writes, pause timers, etc.
    });
}
```

Or use a dedicated listener class:

```
// app/Listeners/SyncOnForeground.php

namespace App\Listeners;

use Djurovicigoor\AppLifecycle\Events\AppForegrounded;
use Illuminate\Support\Facades\Http;

class SyncOnForeground
{
    public function handle(AppForegrounded $event): void
    {

    }
}
```

```
// app/Providers/AppServiceProvider.php

Event::listen(AppForegrounded::class, SyncOnForeground::class);
```

> ⚠️ **NativePHP Mobile has no queue worker.** Do not implement `ShouldQueue` on your listeners — jobs will be written to the database but never processed. Keep listener logic fast and synchronous.

---

### PHP — Livewire Component

[](#php--livewire-component)

Use the `#[On]` attribute with the `native:` prefix in any Livewire component:

```
use Livewire\Attributes\On;
use Livewire\Component;

class Dashboard extends Component
{
    #[On('native:Djurovicigoor\AppLifecycle\Events\AppForegrounded')]
    public function handleForegrounded(int $timestamp): void
    {
        // Refresh data when app returns to foreground
        $this->loadLatestData();
    }

    #[On('native:Djurovicigoor\AppLifecycle\Events\AppBackgrounded')]
    public function handleBackgrounded(int $timestamp): void
    {
        // Save state when app goes to background
        $this->saveCurrentState();
    }
}
```

---

### JavaScript — Vue 3 (Composition API)

[](#javascript--vue-3-composition-api)

```
import { onAppForegrounded, onAppBackgrounded } from '@djurovicigoor/app-lifecycle';
import { onMounted, onUnmounted } from 'vue';

export default {
    setup() {
        let stopFg, stopBg;

        onMounted(() => {
            stopFg = onAppForegrounded(({ timestamp }) => {
                console.log('App is active again', new Date(timestamp));
                // fetch fresh data, restart polling, etc.
            });

            stopBg = onAppBackgrounded(({ timestamp }) => {
                console.log('App went to background', new Date(timestamp));
                // pause timers, cancel requests, etc.
            });
        });

        onUnmounted(() => {
            stopFg?.();
            stopBg?.();
        });
    },
};
```

---

### JavaScript — React

[](#javascript--react)

```
import { onAppForegrounded, onAppBackgrounded } from '@djurovicigoor/app-lifecycle';
import { useEffect } from 'react';

export function Dashboard() {
    useEffect(() => {
        const stopFg = onAppForegrounded(({ timestamp }) => {
            console.log('App foregrounded at', timestamp);
        });

        const stopBg = onAppBackgrounded(({ timestamp }) => {
            console.log('App backgrounded at', timestamp);
        });

        return () => {
            stopFg();
            stopBg();
        };
    }, []);
}
```

---

### JavaScript — Vanilla / Inertia

[](#javascript--vanilla--inertia)

```
import { onAppForegrounded, onAppBackgrounded } from '@djurovicigoor/app-lifecycle';

// Returns an unsubscribe function — call it to clean up
const stopFg = onAppForegrounded(({ timestamp }) => syncData());
const stopBg = onAppBackgrounded(({ timestamp }) => saveState());

// Later, when tearing down:
stopFg();
stopBg();
```

---

Events
------

[](#events)

### `AppForegrounded`

[](#appforegrounded)

Fired when the user returns the app to the foreground after it was previously backgrounded.

> **Note:** This event does **not** fire on initial app launch — only on genuine background → foreground transitions.

**PHP class:** `Djurovicigoor\AppLifecycle\Events\AppForegrounded`

PropertyTypeDescription`$timestamp``int`Unix timestamp in milliseconds when the transition occurred---

### `AppBackgrounded`

[](#appbackgrounded)

Fired when the user leaves the app (presses Home, switches apps, or locks the screen).

**PHP class:** `Djurovicigoor\AppLifecycle\Events\AppBackgrounded`

PropertyTypeDescription`$timestamp``int`Unix timestamp in milliseconds when the transition occurred---

JavaScript API
--------------

[](#javascript-api)

```
import { onAppForegrounded, onAppBackgrounded, Events } from '@djurovicigoor/app-lifecycle';
```

FunctionParametersReturnsDescription`onAppForegrounded(handler)``handler: ({ timestamp: number }) => void``() => void`Subscribe to foreground transitions`onAppBackgrounded(handler)``handler: ({ timestamp: number }) => void``() => void`Subscribe to background transitions`Events.AppLifecycle.AppForegrounded`—`string`PHP class name constant`Events.AppLifecycle.AppBackgrounded`—`string`PHP class name constant---

Platform Behavior
-----------------

[](#platform-behavior)

### Android

[](#android)

- Foreground detection uses `NativePHPLifecycle.ON_RESUME`
- Background detection uses `NativePHPLifecycle.ON_PAUSE`
- The initial `onResume` at app launch is **suppressed** — a `wasBackgrounded` guard ensures only genuine returns fire the event
- NativePHP's activity declares `android:configChanges="uiMode|colorMode|orientation|screenSize"`, so screen rotation does **not** trigger false foreground/background events

### iOS

[](#ios)

- Foreground detection uses `UIApplication.willEnterForegroundNotification`
- Background detection uses `UIApplication.didEnterBackgroundNotification`
- `willEnterForeground` fires only when returning from the background, **not** on initial app launch — no extra guard is needed

---

Plugin Details
--------------

[](#plugin-details)

FieldValueAuthorDjurovic IgorVersion1.0.0LicenseMITAndroid min SDK21iOS min version15.0PlatformsAndroid, iOSNativePHP Mobile`^3.0`PHP`^8.2`Support
=======

[](#support)

For questions or issues, email

License
=======

[](#license)

The MIT License (MIT). Please see License File for more information.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance97

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

14d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a1e2a84a2e5e3b8e5d530168bc9baca101592847f12f89058a9f91c8651648e?d=identicon)[djurovicigoor](/maintainers/djurovicigoor)

---

Top Contributors

[![djurovicigoor](https://avatars.githubusercontent.com/u/15280567?v=4)](https://github.com/djurovicigoor "djurovicigoor (4 commits)")

### Embed Badge

![Health badge](/badges/djurovicigoor-app-lifecycle/health.svg)

```
[![Health](https://phpackages.com/badges/djurovicigoor-app-lifecycle/health.svg)](https://phpackages.com/packages/djurovicigoor-app-lifecycle)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
