Merge pull request #272 from jiongxuan/master

Added "Start Service on Application.onCreate" demo
This commit is contained in:
Cundong 2017-08-01 21:38:11 +08:00 committed by GitHub
commit b613137b5a
3 changed files with 71 additions and 0 deletions

View File

@ -81,6 +81,8 @@
</receiver>
<!-- service -->
<service
android:name=".service.PluginDemoAppService" />
<service
android:name=".service.PluginDemoService1"
android:process=":bg" />

View File

@ -17,6 +17,9 @@
package com.qihoo360.replugin.sample.demo1;
import android.app.Application;
import android.content.Intent;
import com.qihoo360.replugin.sample.demo1.service.PluginDemoAppService;
/**
* @author RePlugin Team
@ -26,5 +29,14 @@ public class MainApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// 在插件启动时就去开启一个服务以模拟个别插件的复杂行为
testStartService();
}
private void testStartService() {
Intent i = new Intent(this, PluginDemoAppService.class);
i.setAction("MyNameIsApp");
startService(i);
}
}

View File

@ -0,0 +1,57 @@
/*
* Copyright (C) 2005-2017 Qihoo 360 Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.qihoo360.replugin.sample.demo1.service;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import com.qihoo360.replugin.sample.demo1.support.LogX;
/**
* @author RePlugin Team
*/
public class PluginDemoAppService extends Service {
public static final String TAG = "demo.service.app";
@Override
public void onCreate() {
super.onCreate();
LogX.logDebug(TAG, "onCreate()");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String action = intent.getAction();
Log.d(TAG, "onStartCommand(): act=" + action);
return super.onStartCommand(intent, flags, startId);
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onDestroy() {
super.onDestroy();
LogX.logDebug(TAG, "onDestroy()");
}
}