File tree Expand file tree Collapse file tree 8 files changed +84
-2
lines changed
Examples/OneSignalDemo/app/src/main
java/com/onesignal/sdktest
OneSignalSDK/onesignal/src/main/java/com/onesignal Expand file tree Collapse file tree 8 files changed +84
-2
lines changed Original file line number Diff line number Diff line change 84
84
85
85
<activity android : name =" .activity.MainActivity" />
86
86
87
+ <activity
88
+ android : name =" .activity.SecondaryActivity"
89
+ android : exported =" false" />
87
90
</application >
88
91
89
92
</manifest >
Original file line number Diff line number Diff line change
1
+ package com .onesignal .sdktest .activity ;
2
+
3
+ import androidx .appcompat .app .AppCompatActivity ;
4
+
5
+ import android .os .Bundle ;
6
+
7
+ import com .onesignal .sdktest .R ;
8
+
9
+ public class SecondaryActivity extends AppCompatActivity {
10
+
11
+ @ Override
12
+ protected void onCreate (Bundle savedInstanceState ) {
13
+ super .onCreate (savedInstanceState );
14
+ setContentView (R .layout .activity_secondary );
15
+ }
16
+ }
Original file line number Diff line number Diff line change 9
9
import androidx .recyclerview .widget .LinearLayoutManager ;
10
10
import androidx .recyclerview .widget .RecyclerView ;
11
11
import androidx .appcompat .widget .Toolbar ;
12
+
13
+ import android .content .Intent ;
12
14
import android .util .Pair ;
13
15
import android .view .View ;
14
16
import android .view .ViewTreeObserver ;
25
27
import com .onesignal .OSSubscriptionStateChanges ;
26
28
import com .onesignal .OneSignal ;
27
29
import com .onesignal .sdktest .R ;
30
+ import com .onesignal .sdktest .activity .SecondaryActivity ;
28
31
import com .onesignal .sdktest .adapter .InAppMessageRecyclerViewAdapter ;
29
32
import com .onesignal .sdktest .adapter .NotificationRecyclerViewAdapter ;
30
33
import com .onesignal .sdktest .adapter .PairRecyclerViewAdapter ;
@@ -244,6 +247,10 @@ public ActivityViewModel onActivityCreated(Context context) {
244
247
pauseInAppMessagesSwitch = getActivity ().findViewById (R .id .main_activity_settings_pause_in_app_messages_switch );
245
248
revokeConsentButton = getActivity ().findViewById (R .id .main_activity_settings_revoke_consent_button );
246
249
250
+ Button navigateNextActivity = getActivity ().findViewById (R .id .main_activity_navigate_button );
251
+ navigateNextActivity .setOnClickListener (v -> {
252
+ getActivity ().startActivity (new Intent (getActivity (), SecondaryActivity .class ));
253
+ });
247
254
tagSet = new HashMap <>();
248
255
tagArrayList = new ArrayList <>();
249
256
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" utf-8" ?>
2
+ <LinearLayout xmlns : android =" http://schemas.android.com/apk/res/android"
3
+ xmlns : tools =" http://schemas.android.com/tools"
4
+ android : layout_width =" match_parent"
5
+ android : layout_height =" match_parent"
6
+ tools : context =" .activity.SecondaryActivity" >
7
+
8
+ </LinearLayout >
Original file line number Diff line number Diff line change 1076
1076
1077
1077
</LinearLayout >
1078
1078
1079
+ <LinearLayout
1080
+ android : layout_width =" match_parent"
1081
+ android : layout_height =" 56dp"
1082
+ android : layout_gravity =" center"
1083
+ android : layout_marginStart =" 16dp"
1084
+ android : layout_marginTop =" 4dp"
1085
+ android : layout_marginEnd =" 16dp"
1086
+ android : layout_marginBottom =" 16dp"
1087
+ android : background =" @color/colorPrimary"
1088
+ android : gravity =" center"
1089
+ android : orientation =" vertical" >
1090
+
1091
+ <Button
1092
+ android : id =" @+id/main_activity_navigate_button"
1093
+ android : layout_width =" match_parent"
1094
+ android : layout_height =" match_parent"
1095
+ android : text =" @string/navigate_next_activity"
1096
+ android : textSize =" 19sp"
1097
+ android : textColor =" @android:color/white"
1098
+ android : background =" @drawable/ripple_selector_white_red"
1099
+ android : visibility =" visible" />
1100
+
1101
+ </LinearLayout >
1079
1102
</LinearLayout >
1080
1103
1081
1104
</androidx .core.widget.NestedScrollView>
Original file line number Diff line number Diff line change 52
52
<string name =" allow" >Allow</string >
53
53
<string name =" revoke_consent" >Revoke Consent</string >
54
54
55
+ <string name =" navigate_next_activity" >Next activity</string >
56
+
55
57
<string name =" onesignal_app_id" >0ba9731b-33bd-43f4-8b59-61172e27447d</string >
56
58
57
59
</resources >
Original file line number Diff line number Diff line change @@ -107,7 +107,6 @@ void onActivityPaused(Activity activity) {
107
107
108
108
void onActivityStopped (Activity activity ) {
109
109
OneSignal .Log (OneSignal .LOG_LEVEL .DEBUG , "onActivityStopped: " + activity );
110
- focusHandler .startOnStopFocusWork ();
111
110
112
111
if (activity == curActivity ) {
113
112
curActivity = null ;
@@ -119,6 +118,9 @@ void onActivityStopped(Activity activity) {
119
118
}
120
119
121
120
logCurActivity ();
121
+
122
+ if (curActivity == null )
123
+ focusHandler .startOnStopFocusWork ();
122
124
}
123
125
124
126
void onActivityDestroyed (Activity activity ) {
Original file line number Diff line number Diff line change @@ -42,21 +42,34 @@ class OSFocusHandler {
42
42
43
43
fun startOnFocusWork () {
44
44
resetBackgroundState()
45
+ OneSignal .onesignalLog(
46
+ OneSignal .LOG_LEVEL .DEBUG ,
47
+ " OSFocusHandler running onAppFocus"
48
+ )
45
49
OneSignal .onAppFocus()
46
50
}
47
51
48
52
fun startOnStartFocusWork () {
49
53
if (stopped) {
50
54
stopped = false
51
- OSTimeoutHandler .getTimeoutHandler().destroyTimeout(stopRunnable)
52
55
stopRunnable = null
56
+ OneSignal .onesignalLog(
57
+ OneSignal .LOG_LEVEL .DEBUG ,
58
+ " OSFocusHandler running onAppStartFocusLogic"
59
+ )
53
60
OneSignal .onAppStartFocusLogic()
61
+ } else {
62
+ resetStopState()
54
63
}
55
64
}
56
65
57
66
fun startOnStopFocusWork () {
58
67
stopRunnable = Runnable {
59
68
stopped = true
69
+ OneSignal .onesignalLog(
70
+ OneSignal .LOG_LEVEL .DEBUG ,
71
+ " OSFocusHandler setting stop state: true"
72
+ )
60
73
}.also {
61
74
OSTimeoutHandler .getTimeoutHandler().startTimeout(stopDelay, it)
62
75
}
@@ -81,7 +94,15 @@ class OSFocusHandler {
81
94
WorkManager .getInstance(context).cancelAllWorkByTag(tag)
82
95
}
83
96
97
+ private fun resetStopState () {
98
+ stopped = false
99
+ stopRunnable?.let {
100
+ OSTimeoutHandler .getTimeoutHandler().destroyTimeout(it)
101
+ }
102
+ }
103
+
84
104
private fun resetBackgroundState () {
105
+ resetStopState()
85
106
backgrounded = false
86
107
}
87
108
You can’t perform that action at this time.
0 commit comments