Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 6160796

Browse files
Fixed #113
1 parent 812a5f0 commit 6160796

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

core/src/main/AndroidManifest.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
<application>
3535
<meta-data android:name="android.max_aspect" android:value="2.1" />
36-
36+
3737
<activity android:name=".activities.CandyBarCrashReport"
3838
android:launchMode="singleInstance"
3939
android:noHistory="true"
@@ -45,6 +45,9 @@
4545
android:configChanges="orientation|keyboardHidden|screenSize"/>
4646

4747
<service android:name=".services.CandyBarWallpapersService" />
48+
49+
<service android:name=".services.CandyBarService"
50+
android:stopWithTask="false"/>
4851
</application>
4952

5053
</manifest>

core/src/main/java/com/dm/material/dashboard/candybar/activities/CandyBarMainActivity.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import com.dm.material.dashboard.candybar.items.Icon;
5757
import com.dm.material.dashboard.candybar.preferences.Preferences;
5858
import com.dm.material.dashboard.candybar.receivers.CandyBarBroadcastReceiver;
59+
import com.dm.material.dashboard.candybar.services.CandyBarService;
5960
import com.dm.material.dashboard.candybar.services.CandyBarWallpapersService;
6061
import com.dm.material.dashboard.candybar.tasks.IconRequestTask;
6162
import com.dm.material.dashboard.candybar.tasks.IconsLoaderTask;
@@ -144,6 +145,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
144145
Preferences.get(this).isDarkTheme() ?
145146
R.color.navigationBarDark : R.color.navigationBar));
146147
registerBroadcastReceiver();
148+
startService(new Intent(this, CandyBarService.class));
147149

148150
//Todo: wait until google fix the issue, then enable wallpaper crop again on API 26+
149151
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@@ -229,7 +231,6 @@ protected void onNewIntent(Intent intent) {
229231
@Override
230232
protected void onResume() {
231233
RequestHelper.checkPiracyApp(this);
232-
Database.get(this.getApplicationContext()).openDatabase();
233234
IntentHelper.sAction = IntentHelper.getAction(getIntent());
234235
super.onResume();
235236
}
@@ -248,6 +249,7 @@ protected void onDestroy() {
248249

249250
CandyBarMainActivity.sMissedApps = null;
250251
CandyBarMainActivity.sHomeIcon = null;
252+
stopService(new Intent(this, CandyBarService.class));
251253
Database.get(this.getApplicationContext()).closeDatabase();
252254
super.onDestroy();
253255
}

core/src/main/java/com/dm/material/dashboard/candybar/applications/CandyBarApplication.java

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import com.dm.material.dashboard.candybar.R;
1010
import com.dm.material.dashboard.candybar.activities.CandyBarCrashReport;
11+
import com.dm.material.dashboard.candybar.databases.Database;
1112
import com.dm.material.dashboard.candybar.helpers.LocaleHelper;
1213
import com.dm.material.dashboard.candybar.items.Request;
1314
import com.dm.material.dashboard.candybar.preferences.Preferences;
@@ -61,6 +62,7 @@ public static Configuration getConfiguration() {
6162
public void onCreate() {
6263
super.onCreate();
6364
mConfiguration = onInit();
65+
Database.get(this).openDatabase();
6466

6567
if (!ImageLoader.getInstance().isInited())
6668
ImageLoader.getInstance().init(ImageConfig.getImageLoaderConfiguration(this));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.dm.material.dashboard.candybar.services;
2+
3+
import android.app.Service;
4+
import android.content.Intent;
5+
import android.os.IBinder;
6+
import android.support.annotation.Nullable;
7+
8+
import com.dm.material.dashboard.candybar.databases.Database;
9+
import com.dm.material.dashboard.candybar.utils.LogUtil;
10+
11+
/*
12+
* CandyBar - Material Dashboard
13+
*
14+
* Copyright (c) 2014-2016 Dani Mahardhika
15+
*
16+
* Licensed under the Apache License, Version 2.0 (the "License");
17+
* you may not use this file except in compliance with the License.
18+
* You may obtain a copy of the License at
19+
*
20+
* http://www.apache.org/licenses/LICENSE-2.0
21+
*
22+
* Unless required by applicable law or agreed to in writing, software
23+
* distributed under the License is distributed on an "AS IS" BASIS,
24+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
* See the License for the specific language governing permissions and
26+
* limitations under the License.
27+
*/
28+
29+
public class CandyBarService extends Service {
30+
31+
@Nullable
32+
@Override
33+
public IBinder onBind(Intent intent) {
34+
return null;
35+
}
36+
37+
@Override
38+
public void onTaskRemoved(Intent rootIntent) {
39+
LogUtil.d("App removed from recent task, database connection closed");
40+
Database.get(this).closeDatabase();
41+
42+
stopSelf();
43+
}
44+
}

0 commit comments

Comments
 (0)