我正在使用IntentService定期执行任务。每次调用此服务后,将剩下三个额外的打开文件。
在adb控制台上,此命令显示PID(进程ID)的所有打开文件:
lsof | busybox grep PID | busybox wc -l
的活动:
public class FileLeakActivity extends Activity {
private Handler handler = new Handler();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
handler.post(mStartService);
}
private Runnable mStartService = new Runnable() {
@Override
public void run() {
Intent svc = new Intent(FileLeakActivity.this, FileLeakService.class);
FileLeakActivity.this.startService(svc);
handler.postDelayed(mStartService, 1000);
}
};
}
服务:
public class FileLeakService extends IntentService {
private final static String TAG = FileLeakService.class.getSimpleName();
public FileLeakService() {
super(TAG);
}
@Override
protected void onHandleIntent(Intent arg0) {
Log.v(TAG, "onHandleIntent");
}
}
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.android.fileleak"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<service android:name="FileLeakService" />
<activity
android:name=".FileLeakActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我做错了什么?