Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
flutter_boost_1.22.4
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李增强
flutter_boost_1.22.4
Commits
e6f711a1
Commit
e6f711a1
authored
Oct 24, 2019
by
yangwu.jia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add BoostLifecycleListener
parent
45482261
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
15 deletions
+64
-15
android/src/main/java/com/idlefish/flutterboost/NewFlutterBoost.java
.../main/java/com/idlefish/flutterboost/NewFlutterBoost.java
+37
-14
android/src/main/java/com/idlefish/flutterboost/Platform.java
...oid/src/main/java/com/idlefish/flutterboost/Platform.java
+1
-0
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/MyApplication.java
...om/taobao/idlefish/flutterboostexample/MyApplication.java
+26
-1
No files found.
android/src/main/java/com/idlefish/flutterboost/NewFlutterBoost.java
View file @
e6f711a1
...
...
@@ -64,7 +64,7 @@ public class NewFlutterBoost {
if
(
mCurrentActiveActivity
==
null
)
{
Debuger
.
log
(
"Application entry foreground"
);
if
(
NewFlutterBoost
.
instance
().
engineProvider
()
!=
null
)
{
if
(
createEngine
()
!=
null
)
{
HashMap
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"type"
,
"foreground"
);
channel
().
sendEvent
(
"lifecycle"
,
map
);
...
...
@@ -88,7 +88,7 @@ public class NewFlutterBoost {
if
(
mCurrentActiveActivity
==
activity
)
{
Debuger
.
log
(
"Application entry background"
);
if
(
engineProvider
()
!=
null
)
{
if
(
createEngine
()
!=
null
)
{
HashMap
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"type"
,
"background"
);
channel
().
sendEvent
(
"lifecycle"
,
map
);
...
...
@@ -107,7 +107,7 @@ public class NewFlutterBoost {
if
(
mCurrentActiveActivity
==
activity
)
{
Debuger
.
log
(
"Application entry background"
);
if
(
engineProvider
()
!=
null
)
{
if
(
createEngine
()
!=
null
)
{
HashMap
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"type"
,
"background"
);
channel
().
sendEvent
(
"lifecycle"
,
map
);
...
...
@@ -131,8 +131,10 @@ public class NewFlutterBoost {
if
(
mEngine
!=
null
)
return
;
FlutterEngine
flutterEngine
=
engineProvider
();
FlutterEngine
flutterEngine
=
createEngine
();
if
(
mPlatform
.
lifecycleListener
!=
null
){
mPlatform
.
lifecycleListener
.
onEngineCreated
();
}
if
(
flutterEngine
.
getDartExecutor
().
isExecutingDart
())
{
// No warning is logged because this situation will happen on every config
// change if the developer does not choose to retain the Fragment instance.
...
...
@@ -154,12 +156,16 @@ public class NewFlutterBoost {
);
flutterEngine
.
getDartExecutor
().
executeDartEntrypoint
(
entrypoint
);
mRegistry
=
new
BoostPluginRegistry
(
engineProvider
(),
mPlatform
.
getApplication
());
mRegistry
=
new
BoostPluginRegistry
(
createEngine
(),
mPlatform
.
getApplication
());
((
BoostPluginRegistry
)
mRegistry
).
currentActivity
(
mCurrentActiveActivity
);
mPlatform
.
registerPlugins
(
mRegistry
);
if
(
mPlatform
.
lifecycleListener
!=
null
){
mPlatform
.
lifecycleListener
.
onPluginsRegistered
();
}
}
...
...
@@ -172,13 +178,12 @@ public class NewFlutterBoost {
public
static
int
ANY_ACTIVITY_CREATED
=
1
;
//当有任何Activity创建时,启动引擎
public
static
int
FLUTTER_ACTIVITY_CREATED
=
2
;
//当有
任何
Activity创建时,启动引擎
public
static
int
FLUTTER_ACTIVITY_CREATED
=
2
;
//当有
flutter
Activity创建时,启动引擎
public
static
int
APP_EXit
=
0
;
//所有flutter Activity destory 时,销毁engine
public
static
int
All_FLUTTER_ACTIVITY_DESTROY
=
1
;
//所有flutter Activity destory 时,销毁engine
private
String
dartEntrypoint
=
DEFAULT_DART_ENTRYPOINT
;
private
String
initialRoute
=
DEFAULT_INITIAL_ROUTE
;
private
int
whenEngineStart
=
ANY_ACTIVITY_CREATED
;
...
...
@@ -193,6 +198,8 @@ public class NewFlutterBoost {
private
INativeRouter
router
=
null
;
private
BoostLifecycleListener
lifecycleListener
;
public
ConfigBuilder
(
Application
app
,
INativeRouter
router
)
{
this
.
router
=
router
;
this
.
mApp
=
app
;
...
...
@@ -218,14 +225,19 @@ public class NewFlutterBoost {
return
this
;
}
public
ConfigBuilder
whenEngineStart
(
@NonNull
int
whenEngineStart
)
{
public
ConfigBuilder
whenEngineStart
(
int
whenEngineStart
)
{
this
.
whenEngineStart
=
whenEngineStart
;
return
this
;
}
public
ConfigBuilder
whenEngineDestory
(
@NonNull
int
whenEngineDestory
)
{
public
ConfigBuilder
whenEngineDestory
(
int
whenEngineDestory
)
{
this
.
whenEngineDestory
=
whenEngineDestory
;
return
this
;
}
public
ConfigBuilder
lifecycleListener
(
BoostLifecycleListener
lifecycleListener
)
{
this
.
lifecycleListener
=
lifecycleListener
;
return
this
;
}
public
Platform
build
()
{
Platform
platform
=
new
Platform
()
{
...
...
@@ -263,6 +275,8 @@ public class NewFlutterBoost {
}
};
platform
.
lifecycleListener
=
this
.
lifecycleListener
;
return
platform
;
}
...
...
@@ -293,8 +307,7 @@ public class NewFlutterBoost {
return
mRegistry
;
}
public
FlutterEngine
engineProvider
()
{
private
FlutterEngine
createEngine
(){
if
(
mEngine
==
null
)
{
FlutterMain
.
startInitialization
(
mPlatform
.
getApplication
());
...
...
@@ -304,23 +317,33 @@ public class NewFlutterBoost {
mPlatform
.
getApplication
().
getApplicationContext
(),
flutterShellArgs
.
toArray
());
mEngine
=
new
FlutterEngine
(
mPlatform
.
getApplication
().
getApplicationContext
());
}
return
mEngine
;
}
public
FlutterEngine
engineProvider
()
{
return
mEngine
;
}
public
void
boostDestroy
(){
if
(
mEngine
!=
null
){
mEngine
.
destroy
();
}
if
(
mPlatform
.
lifecycleListener
!=
null
){
mPlatform
.
lifecycleListener
.
onEngineDestroy
();
}
mEngine
=
null
;
mRegistry
=
null
;
mCurrentActiveActivity
=
null
;
}
public
interface
BoostLifecycleListener
{
void
onEngineCreated
();
void
onPluginsRegistered
();
void
onEngineDestroy
();
}
}
android/src/main/java/com/idlefish/flutterboost/Platform.java
View file @
e6f711a1
...
...
@@ -25,6 +25,7 @@ public abstract class Platform {
public
abstract
String
initialRoute
();
public
NewFlutterBoost
.
BoostLifecycleListener
lifecycleListener
;
public
void
closeContainer
(
IContainerRecord
record
,
Map
<
String
,
Object
>
result
,
Map
<
String
,
Object
>
exts
)
{
if
(
record
==
null
)
return
;
...
...
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/MyApplication.java
View file @
e6f711a1
...
...
@@ -3,6 +3,7 @@ package com.taobao.idlefish.flutterboostexample;
import
android.app.Application
;
import
android.content.Context
;
import
android.util.Log
;
import
com.idlefish.flutterboost.*
;
import
com.idlefish.flutterboost.interfaces.IContainerRecord
;
...
...
@@ -10,12 +11,14 @@ import java.util.Map;
import
com.idlefish.flutterboost.interfaces.INativeRouter
;
import
io.flutter.app.FlutterApplication
;
import
io.flutter.plugin.common.MethodChannel
;
public
class
MyApplication
extends
Application
{
@Override
public
void
onCreate
()
{
super
.
onCreate
();
INativeRouter
router
=
new
INativeRouter
()
{
@Override
public
void
openContainer
(
Context
context
,
String
url
,
Map
<
String
,
Object
>
urlParams
,
int
requestCode
,
Map
<
String
,
Object
>
exts
)
{
...
...
@@ -25,12 +28,34 @@ public class MyApplication extends Application {
};
NewFlutterBoost
.
BoostLifecycleListener
lifecycleListener
=
new
NewFlutterBoost
.
BoostLifecycleListener
()
{
@Override
public
void
onEngineCreated
()
{
}
@Override
public
void
onPluginsRegistered
()
{
MethodChannel
mMethodChannel
=
new
MethodChannel
(
NewFlutterBoost
.
instance
().
engineProvider
().
getDartExecutor
(),
"boosttest"
);
Log
.
e
(
"MyApplication"
,
"MethodChannel create"
);
}
@Override
public
void
onEngineDestroy
()
{
}
};
Platform
platform
=
new
NewFlutterBoost
.
ConfigBuilder
(
this
,
router
)
.
isDebug
(
true
)
.
whenEngineStart
(
NewFlutterBoost
.
ConfigBuilder
.
ANY_ACTIVITY_CREATED
)
.
lifecycleListener
(
lifecycleListener
)
.
build
();
NewFlutterBoost
.
instance
().
init
(
platform
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment