Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | List of all members
flutter::NativeActivity Class Reference

An instance of a native activity. Users of the native_activity_apk are meant to subclass this and return an instance of this subclass from flutter::NativeActivityMain. More...

#include <native_activity.h>

Inheritance diagram for flutter::NativeActivity:
flutter::GTestActivity

Public Member Functions

virtual ~NativeActivity ()
 
void Terminate ()
 Perform graceful termination of the activity. Will eventually lead to the other activity lifecycle callback on the way to termination. More...
 
virtual void OnStart ()
 
virtual void OnStop ()
 
virtual void OnPause ()
 
virtual void OnResume ()
 
virtual std::shared_ptr< fml::MappingOnSaveInstanceState ()
 
virtual void OnWindowFocusChanged (bool has_focus)
 
virtual void OnNativeWindowCreated (ANativeWindow *window)
 
virtual void OnNativeWindowResized (ANativeWindow *window)
 
virtual void OnNativeWindowRedrawNeeded (ANativeWindow *window)
 
virtual void OnNativeWindowDestroyed (ANativeWindow *window)
 
virtual void OnInputQueueCreated (AInputQueue *queue)
 
virtual void OnInputQueueDestroyed (AInputQueue *queue)
 
virtual void OnConfigurationChanged ()
 
virtual void OnLowMemory ()
 

Protected Member Functions

 NativeActivity (ANativeActivity *activity)
 

Detailed Description

An instance of a native activity. Users of the native_activity_apk are meant to subclass this and return an instance of this subclass from flutter::NativeActivityMain.

All methods are called on the Android Platform main-thread. Subclasses will usually re-thread calls to a background thread for long running tasks as these will lead to ANRs on when invoked on the platform thread.

Definition at line 25 of file native_activity.h.

Constructor & Destructor Documentation

◆ ~NativeActivity()

flutter::NativeActivity::~NativeActivity ( )
virtualdefault

◆ NativeActivity()

flutter::NativeActivity::NativeActivity ( ANativeActivity *  activity)
explicitprotected

Definition at line 11 of file native_activity.cc.

12 : activity_(activity) {
14
15 activity->instance = this;
16
17 activity->callbacks->onStart = [](ANativeActivity* activity) {
18 reinterpret_cast<NativeActivity*>(activity->instance)->OnStart();
19 };
20 activity->callbacks->onStop = [](ANativeActivity* activity) {
21 reinterpret_cast<NativeActivity*>(activity->instance)->OnStop();
22 };
23 activity->callbacks->onPause = [](ANativeActivity* activity) {
24 reinterpret_cast<NativeActivity*>(activity->instance)->OnPause();
25 };
26 activity->callbacks->onResume = [](ANativeActivity* activity) {
27 reinterpret_cast<NativeActivity*>(activity->instance)->OnResume();
28 };
29 activity->callbacks->onDestroy = [](ANativeActivity* activity) {
30 delete reinterpret_cast<NativeActivity*>(activity->instance);
31 };
32 activity->callbacks->onSaveInstanceState = [](ANativeActivity* activity,
33 size_t* out_size) -> void* {
34 auto mapping = reinterpret_cast<NativeActivity*>(activity->instance)
36 if (mapping == nullptr || mapping->GetMapping() == nullptr) {
37 *out_size = 0;
38 return nullptr;
39 }
40
41 // This will be `free`d by the framework.
42 auto copied = malloc(mapping->GetSize());
43 FML_CHECK(copied != nullptr)
44 << "Allocation failure while saving instance state.";
45 memcpy(copied, mapping->GetMapping(), mapping->GetSize());
46 *out_size = mapping->GetSize();
47 return copied;
48 };
49 activity->callbacks->onWindowFocusChanged = [](ANativeActivity* activity,
50 int has_focus) {
51 reinterpret_cast<NativeActivity*>(activity->instance)
52 ->OnWindowFocusChanged(has_focus);
53 };
54 activity->callbacks->onNativeWindowCreated = [](ANativeActivity* activity,
56 reinterpret_cast<NativeActivity*>(activity->instance)
58 };
59 activity->callbacks->onNativeWindowResized = [](ANativeActivity* activity,
61 reinterpret_cast<NativeActivity*>(activity->instance)
63 };
64 activity->callbacks->onNativeWindowRedrawNeeded =
65 [](ANativeActivity* activity, ANativeWindow* window) {
66 reinterpret_cast<NativeActivity*>(activity->instance)
68 };
69 activity->callbacks->onNativeWindowDestroyed = [](ANativeActivity* activity,
71 reinterpret_cast<NativeActivity*>(activity->instance)
73 };
74 activity->callbacks->onInputQueueCreated = [](ANativeActivity* activity,
75 AInputQueue* queue) {
76 reinterpret_cast<NativeActivity*>(activity->instance)
78 };
79 activity->callbacks->onInputQueueDestroyed = [](ANativeActivity* activity,
80 AInputQueue* queue) {
81 reinterpret_cast<NativeActivity*>(activity->instance)
83 };
84 activity->callbacks->onConfigurationChanged = [](ANativeActivity* activity) {
85 reinterpret_cast<NativeActivity*>(activity->instance)
87 };
88 activity->callbacks->onLowMemory = [](ANativeActivity* activity) {
89 reinterpret_cast<NativeActivity*>(activity->instance)->OnLowMemory();
90 };
91}
virtual void OnNativeWindowCreated(ANativeWindow *window)
virtual void OnNativeWindowResized(ANativeWindow *window)
virtual void OnInputQueueDestroyed(AInputQueue *queue)
virtual void OnNativeWindowRedrawNeeded(ANativeWindow *window)
virtual void OnNativeWindowDestroyed(ANativeWindow *window)
NativeActivity(ANativeActivity *activity)
virtual void OnInputQueueCreated(AInputQueue *queue)
virtual void OnConfigurationChanged()
virtual std::shared_ptr< fml::Mapping > OnSaveInstanceState()
virtual void OnWindowFocusChanged(bool has_focus)
static void EnsureInitializedForCurrentThread()
Definition: message_loop.cc:27
GLFWwindow * window
Definition: main.cc:45
VkQueue queue
Definition: main.cc:55
#define FML_CHECK(condition)
Definition: logging.h:85
void * malloc(size_t size)
Definition: allocation.cc:19
struct ANativeWindow ANativeWindow

Member Function Documentation

◆ OnConfigurationChanged()

void flutter::NativeActivity::OnConfigurationChanged ( )
virtual

Definition at line 121 of file native_activity.cc.

121{}

◆ OnInputQueueCreated()

void flutter::NativeActivity::OnInputQueueCreated ( AInputQueue *  queue)
virtual

Definition at line 117 of file native_activity.cc.

117{}

◆ OnInputQueueDestroyed()

void flutter::NativeActivity::OnInputQueueDestroyed ( AInputQueue *  queue)
virtual

Definition at line 119 of file native_activity.cc.

119{}

◆ OnLowMemory()

void flutter::NativeActivity::OnLowMemory ( )
virtual

Definition at line 123 of file native_activity.cc.

123{}

◆ OnNativeWindowCreated()

void flutter::NativeActivity::OnNativeWindowCreated ( ANativeWindow window)
virtual

Reimplemented in flutter::GTestActivity.

Definition at line 109 of file native_activity.cc.

109{}

◆ OnNativeWindowDestroyed()

void flutter::NativeActivity::OnNativeWindowDestroyed ( ANativeWindow window)
virtual

Definition at line 115 of file native_activity.cc.

115{}

◆ OnNativeWindowRedrawNeeded()

void flutter::NativeActivity::OnNativeWindowRedrawNeeded ( ANativeWindow window)
virtual

Definition at line 113 of file native_activity.cc.

113{}

◆ OnNativeWindowResized()

void flutter::NativeActivity::OnNativeWindowResized ( ANativeWindow window)
virtual

Definition at line 111 of file native_activity.cc.

111{}

◆ OnPause()

void flutter::NativeActivity::OnPause ( )
virtual

Definition at line 99 of file native_activity.cc.

99{}

◆ OnResume()

void flutter::NativeActivity::OnResume ( )
virtual

Definition at line 101 of file native_activity.cc.

101{}

◆ OnSaveInstanceState()

std::shared_ptr< fml::Mapping > flutter::NativeActivity::OnSaveInstanceState ( )
virtual

Definition at line 103 of file native_activity.cc.

103 {
104 return nullptr;
105}

◆ OnStart()

void flutter::NativeActivity::OnStart ( )
virtual

Definition at line 95 of file native_activity.cc.

95{}

◆ OnStop()

void flutter::NativeActivity::OnStop ( )
virtual

Definition at line 97 of file native_activity.cc.

97{}

◆ OnWindowFocusChanged()

void flutter::NativeActivity::OnWindowFocusChanged ( bool  has_focus)
virtual

Definition at line 107 of file native_activity.cc.

107{}

◆ Terminate()

void flutter::NativeActivity::Terminate ( )

Perform graceful termination of the activity. Will eventually lead to the other activity lifecycle callback on the way to termination.

Can be called from any thread.

Definition at line 125 of file native_activity.cc.

125 {
126 ANativeActivity_finish(activity_);
127}

The documentation for this class was generated from the following files: