5#include "flutter/testing/android/native_activity/native_activity.h"
7#include "flutter/fml/message_loop.h"
12 : activity_(activity) {
15 activity->instance =
this;
17 activity->callbacks->onStart = [](ANativeActivity* activity) {
20 activity->callbacks->onStop = [](ANativeActivity* activity) {
23 activity->callbacks->onPause = [](ANativeActivity* activity) {
26 activity->callbacks->onResume = [](ANativeActivity* activity) {
29 activity->callbacks->onDestroy = [](ANativeActivity* activity) {
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) {
42 auto copied =
malloc(mapping->GetSize());
44 <<
"Allocation failure while saving instance state.";
45 memcpy(copied, mapping->GetMapping(), mapping->GetSize());
46 *out_size = mapping->GetSize();
49 activity->callbacks->onWindowFocusChanged = [](ANativeActivity* activity,
54 activity->callbacks->onNativeWindowCreated = [](ANativeActivity* activity,
59 activity->callbacks->onNativeWindowResized = [](ANativeActivity* activity,
64 activity->callbacks->onNativeWindowRedrawNeeded =
69 activity->callbacks->onNativeWindowDestroyed = [](ANativeActivity* activity,
74 activity->callbacks->onInputQueueCreated = [](ANativeActivity* activity,
79 activity->callbacks->onInputQueueDestroyed = [](ANativeActivity* activity,
84 activity->callbacks->onConfigurationChanged = [](ANativeActivity* activity) {
88 activity->callbacks->onLowMemory = [](ANativeActivity* activity) {
126 ANativeActivity_finish(activity_);
131extern "C" __attribute__((visibility(
"default"))) void ANativeActivity_onCreate(
132 ANativeActivity* activity,
135 std::unique_ptr<fml::Mapping> saved_state_mapping;
137 saved_state_mapping = std::make_unique<fml::MallocMapping>(
An instance of a native activity. Users of the native_activity_apk are meant to subclass this and ret...
virtual ~NativeActivity()
virtual void OnNativeWindowCreated(ANativeWindow *window)
virtual void OnNativeWindowResized(ANativeWindow *window)
void Terminate()
Perform graceful termination of the activity. Will eventually lead to the other activity lifecycle ca...
virtual void OnInputQueueDestroyed(AInputQueue *queue)
virtual void OnNativeWindowRedrawNeeded(ANativeWindow *window)
virtual void OnNativeWindowDestroyed(ANativeWindow *window)
virtual void OnLowMemory()
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 MallocMapping Copy(const T *begin, const T *end)
static void EnsureInitializedForCurrentThread()
#define FML_CHECK(condition)
void * malloc(size_t size)
std::unique_ptr< NativeActivity > NativeActivityMain(ANativeActivity *activity, std::unique_ptr< fml::Mapping > saved_state)
__attribute__((visibility("default"))) void ANativeActivity_onCreate(ANativeActivity *activity
void size_t saved_state_size
struct ANativeWindow ANativeWindow