android_activity_lifecycle 0.0.2 copy "android_activity_lifecycle: ^0.0.2" to clipboard
android_activity_lifecycle: ^0.0.2 copied to clipboard

PlatformAndroid

This flutter plugin for listen to FlutterActivity lifecycle state change on flutter Android app

example/lib/main.dart

import 'dart:developer';

import 'package:flutter/material.dart';

import 'package:android_activity_lifecycle/android_activity_lifecycle.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _nAndroidLifecyclePlugin = AndroidActivityLifecycle();

  @override
  void initState() {
    super.initState();
    _nAndroidLifecyclePlugin.setMethodCallHandler((call) async {
      String message = "Unknown";
      bool result = true;
      switch (call.method) {
        case "onCreate":
          message = ("dart ${call.method} ${call.arguments}");
          break;
        case "onStart":
          message = ("dart ${call.method} ${call.arguments}");
          break;
        case "onResume":
          message = ("dart ${call.method} ${call.arguments}");
          break;
        case "onPause":
          message = ("dart ${call.method} ${call.arguments}");
          break;
        case "onStop":
          message = ("dart ${call.method} ${call.arguments}");
          break;
        case "onDestroy":
          message = ("dart ${call.method} ${call.arguments}");
          break;
        default:
          result = false;
      }
      log(message);
      return result;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: const Center(
          child: Column(
            children: [
              Text('Open logging for more information\n'),
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
155
points
41
downloads

Publisher

unverified uploader

Weekly Downloads

This flutter plugin for listen to FlutterActivity lifecycle state change on flutter Android app

Homepage
Repository (GitHub)
View/report issues

Topics

#platform-channels #plugin-development

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, flutter_plugin_android_lifecycle, plugin_platform_interface

More

Packages that depend on android_activity_lifecycle

Packages that implement android_activity_lifecycle