mirror of
https://gitee.com/replugin/RePlugin.git
synced 2024-11-30 02:38:34 +08:00
Merge pull request #272 from jiongxuan/master
Added "Start Service on Application.onCreate" demo
This commit is contained in:
commit
b613137b5a
@ -81,6 +81,8 @@
|
||||
</receiver>
|
||||
|
||||
<!-- service -->
|
||||
<service
|
||||
android:name=".service.PluginDemoAppService" />
|
||||
<service
|
||||
android:name=".service.PluginDemoService1"
|
||||
android:process=":bg" />
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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()");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user