即使使用前台服务,我的 android 应用程序也会在后台被杀死。这是漏洞清单:
<?xml version="1.0" encoding="utf-8"?>
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" >
</supports-screens>
<application
android:debuggable="true"
android:icon="@drawable/icon"
android:label="TritonHK"
android:theme="@android:style/Theme.NoTitleBar" >
<activity
android:name=".LoginActivity"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyService"
android:icon="@drawable/icon"
android:label="TritonHK"
android:process=":my_process" >
</service>
<activity
android:name="Setting"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="MenuScreen"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="TaskSheetList"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="TaskDetails"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="CreditsList"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="SectionsList"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="SuperDashboard"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="InspectionActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="Inbox"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="InspectionDetail"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="StaffListView"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="MultiTaskSheetListView"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="CheckListItemDetails"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="OpenJobs"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="GuestDetails"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="MessageList"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ImageCollectionActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="NewBGMessages"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
</application>
<!-- Added for 4.1 Android os -->
<uses-sdk android:minSdkVersion="7" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.telephony" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.CALL_PHONE" >
</uses-permission>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SET_WALLPAPER" >
</uses-permission>
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
这是代码service
MLog.w(getClass().getName(), "TritonHK started");
Notification note=new Notification(R.drawable.icon,
"TritonHK is running",
System.currentTimeMillis());
Intent i=new Intent(this, BGMessages.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pi=PendingIntent.getActivity(this, 0,
i, 0);
note.setLatestEventInfo(this, "TritonHK",
"TritonHK",
pi);
note.flags|=Notification.FLAG_NO_CLEAR;
startForeground(1337, note);
这就是我开始我的方式service
:
Intent i=new Intent(this, MyService.class);
startService(i);
这是刚刚被杀死时的logcat:
02-05 10:04:16.676 D/dalvikvm(20458): GC_CONCURRENT freed 2010K, 54% free 3862K/8327K, external 11961K/14009K, paused 13ms+2ms
02-05 10:04:20.576 D/dalvikvm(19610): GC_CONCURRENT freed 511K, 52% free 2973K/6151K, external 2171K/2711K, paused 2ms+2ms
02-05 10:04:28.256 D/dalvikvm(19610): GC_CONCURRENT freed 449K, 52% free 2966K/6151K, external 2112K/2638K, paused 2ms+11ms
02-05 10:04:32.626 D/dalvikvm(20458): GC_CONCURRENT freed 1970K, 54% free 3862K/8327K, external 11961K/14009K, paused 7ms+2ms
02-05 10:04:43.216 D/dalvikvm(19610): GC_CONCURRENT freed 498K, 52% free 2974K/6151K, external 2140K/2672K, paused 2ms+2ms
02-05 10:04:48.266 D/dalvikvm(20458): GC_CONCURRENT freed 1974K, 54% free 3869K/8327K, external 11961K/14009K, paused 3ms+3ms
02-05 10:04:58.746 D/dalvikvm(19610): GC_CONCURRENT freed 510K, 52% free 2973K/6151K, external 2140K/2672K, paused 1ms+2ms
02-05 10:05:00.176 D/kernel ( 120): [40912.899353] max17040 0-0036: batt:100%, 4126 mV
02-05 10:05:03.686 D/dalvikvm(20458): GC_CONCURRENT freed 1979K, 54% free 3862K/8327K, external 11961K/14009K, paused 7ms+3ms
02-05 10:05:13.616 D/dalvikvm(19610): GC_CONCURRENT freed 510K, 52% free 2973K/6151K, external 2202K/2750K, paused 2ms+2ms
02-05 10:05:19.706 D/dalvikvm(20458): GC_CONCURRENT freed 1970K, 54% free 3862K/8327K, external 11961K/14009K, paused 14ms+2ms
02-05 10:05:21.346 D/dalvikvm(19610): GC_CONCURRENT freed 449K, 52% free 2962K/6151K, external 2112K/2638K, paused 2ms+3ms
02-05 10:05:35.526 D/dalvikvm(20458): GC_CONCURRENT freed 2038K, 54% free 3871K/8327K, external 11961K/14009K, paused 1ms+3ms
02-05 10:05:36.676 D/skia (20458): purging 194K from font cache [25 entries]
02-05 10:05:36.936 D/dalvikvm(19610): GC_CONCURRENT freed 498K, 52% free 2974K/6151K, external 2202K/2750K, paused 1ms+5ms
02-05 10:05:44.656 D/dalvikvm( 238): GC_CONCURRENT freed 1828K, 42% free 7427K/12743K, external 6677K/8035K, paused 5ms+20ms
02-05 10:05:46.206 I/ActivityManager( 238): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10100000 cmp=com.tritonhk.android/.LoginActivity } from pid 238
02-05 10:05:46.266 I/ActivityManager( 238): Start proc com.tritonhk.android for activity com.tritonhk.android/.TaskDetails: pid=20479 uid=10124 gids={1006, 3003, 1015}
02-05 10:05:46.336 W/InputManagerService( 238): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@2b4a1708
我正在开始我service
的.onCreate
first activity
请帮助我。