Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
Sobot_module_Dev
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sobot_android
Sobot_module_Dev
Commits
b4372306
Commit
b4372306
authored
Jan 13, 2024
by
zhengnw@sobot.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
widget 1.1.5 添加ActivityLifeCycle 检测app被系统回收(强杀)状态
parent
61bd877d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
132 additions
and
1 deletion
+132
-1
sobot-widget-publish-mavencentral.gradle
sobot_widget/sobot-widget-publish-mavencentral.gradle
+1
-1
SobotActivityLifeCycle.java
...com/sobot/widget/myappliction/SobotActivityLifeCycle.java
+125
-0
SobotAppStatusConstant.java
...com/sobot/widget/myappliction/SobotAppStatusConstant.java
+6
-0
No files found.
sobot_widget/sobot-widget-publish-mavencentral.gradle
View file @
b4372306
...
...
@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) {
ext
{
PUBLISH_GROUP_ID
=
"com.sobot.library"
//项目包名
PUBLISH_ARTIFACT_ID
=
'widget_x'
//项目名
PUBLISH_VERSION
=
'1.1.
4
'
//版本号
PUBLISH_VERSION
=
'1.1.
5
'
//版本号
}
...
...
sobot_widget/src/main/java/com/sobot/widget/myappliction/SobotActivityLifeCycle.java
0 → 100644
View file @
b4372306
package
com
.
sobot
.
widget
.
myappliction
;
import
android.app.Activity
;
import
android.app.Application
;
import
android.os.Bundle
;
import
android.util.Log
;
import
com.sobot.utils.SobotLogUtils
;
import
java.lang.ref.WeakReference
;
/**
* app 管理类
* 可判断 app被系统回收(强杀)状态;app是否前台
*/
public
class
SobotActivityLifeCycle
implements
Application
.
ActivityLifecycleCallbacks
{
//默认被初始化状态,被系统回收(强杀)状态
public
int
mAppStatus
=
SobotAppStatusConstant
.
STATUS_FORCE_KILLED
;
private
boolean
mPaused
=
true
;
private
boolean
mForeground
=
false
;
private
static
SobotActivityLifeCycle
sInstance
;
//当前Activity的弱引用
private
WeakReference
<
Activity
>
mActivityReference
;
protected
final
String
TAG
=
"SobotActivityLifeCycle"
;
public
static
final
int
ACTIVITY_ON_RESUME
=
0
;
public
static
final
int
ACTIVITY_ON_PAUSE
=
1
;
//打开的Activity数量统计
private
int
activityStartCount
=
0
;
private
SobotActivityLifeCycle
()
{
}
public
static
synchronized
SobotActivityLifeCycle
getInstance
()
{
if
(
sInstance
==
null
)
{
sInstance
=
new
SobotActivityLifeCycle
();
}
return
sInstance
;
}
/**
* 获取APP状态
*
* @return
*/
public
int
getAppStatus
()
{
return
mAppStatus
;
}
/**
* 设置APP状态
*
* @param appStatus
*/
public
void
setAppStatus
(
int
appStatus
)
{
this
.
mAppStatus
=
appStatus
;
}
public
Activity
getCurrentActivity
()
{
if
(
mActivityReference
!=
null
)
{
return
mActivityReference
.
get
();
}
return
null
;
}
public
boolean
isForground
()
{
return
mForeground
;
}
@Override
public
void
onActivityCreated
(
Activity
activity
,
Bundle
savedInstanceState
)
{
Log
.
d
(
TAG
,
activity
.
getLocalClassName
()
+
" "
+
"onActivityCreated"
);
mActivityReference
=
new
WeakReference
<
Activity
>(
activity
);
}
@Override
public
void
onActivityStarted
(
Activity
activity
)
{
Log
.
d
(
TAG
,
activity
.
getLocalClassName
()
+
" "
+
"onActivityStarted"
);
activityStartCount
++;
//数值从0变到1说明是从后台切到前台
if
(
activityStartCount
==
1
)
{
//从后台切到前台
SobotLogUtils
.
i
(
"从后台切到前台"
);
}
}
@Override
public
void
onActivityResumed
(
Activity
activity
)
{
String
activityName
=
activity
.
getClass
().
getName
();
mPaused
=
false
;
mForeground
=
true
;
mActivityReference
=
new
WeakReference
<
Activity
>(
activity
);
}
@Override
public
void
onActivityPaused
(
Activity
activity
)
{
//pause事件后是否在前台要分情况判断
mPaused
=
true
;
}
@Override
public
void
onActivityStopped
(
Activity
activity
)
{
Log
.
d
(
TAG
,
activity
.
getLocalClassName
()
+
" "
+
"onActivityStopped"
);
activityStartCount
--;
//数值从1到0说明是从前台切到后台
if
(
activityStartCount
==
0
)
{
//从前台切到后台
SobotLogUtils
.
i
(
"从前台切到后台"
);
}
}
@Override
public
void
onActivitySaveInstanceState
(
Activity
activity
,
Bundle
outState
)
{
}
@Override
public
void
onActivityDestroyed
(
Activity
activity
)
{
Log
.
d
(
TAG
,
activity
.
getLocalClassName
()
+
" "
+
"onActivityDestroyed"
);
}
}
sobot_widget/src/main/java/com/sobot/widget/myappliction/SobotAppStatusConstant.java
0 → 100644
View file @
b4372306
package
com
.
sobot
.
widget
.
myappliction
;
public
class
SobotAppStatusConstant
{
public
static
final
int
STATUS_FORCE_KILLED
=
-
1
;
//应用放在后台被强杀了
public
static
final
int
STATUS_NORMAL
=
1
;
//APP正常态
}
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