Skip to content

Commit 3237641

Browse files
committed
Update Demo ,service暂不支持多个,后续通过代理的方式来支持
Signed-off-by: limpoxe <405977146@163.com>
1 parent c0c1eee commit 3237641

File tree

5 files changed

+77
-13
lines changed

5 files changed

+77
-13
lines changed
233 Bytes
Binary file not shown.

PluginMain/src/com/example/pluginmain/PluginDetailActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void onClick(View v) {
133133
// PluginDispatcher.startService(PluginDetailActivity.this,
134134
// intent);
135135
startService(intent);
136-
stopService(intent);
136+
// stopService(intent);
137137
} else if (entry.contains("Receiver")) {// 这个判断仅仅是为了方便debug,在实际开发中,类型一定是已知的
138138

139139
Intent intent = new Intent();

PluginTest/AndroidManifest.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@
9999
</intent-filter>
100100
</service>
101101

102+
<service android:name="com.example.plugintest.service.PluginTestService2">
103+
<intent-filter>
104+
<action
105+
android:name="test.lmn2" />
106+
107+
<category
108+
android:name="android.intent.category.DEFAULT" />
109+
</intent-filter>
110+
</service>
102111

103112
<receiver android:name="com.example.plugintest.receiver.PluginTestReceiver" >
104113
<intent-filter>

PluginTest/src/com/example/plugintest/service/PluginTestService.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,33 @@ public void onCreate() {
2121
super.onCreate();
2222
Log.d("PluginTestService", "PluginTestService onCreate");
2323
}
24-
24+
2525
@Override
2626
public int onStartCommand(Intent intent, int flags, int startId) {
27-
28-
Log.d("PluginTestService", "PluginTestService onStartCommand "
29-
+ (intent == null?" null" : intent.toUri(0))
30-
+ " " + getResources().getText(R.string.hello_world3));
31-
32-
Toast.makeText(this, " PluginTestService "
33-
+ (intent == null?" null" : intent.toUri(0)), Toast.LENGTH_LONG).show();
34-
27+
28+
Log.d("PluginTestService", "PluginTestService onStartCommand " + (intent == null ? " null" : intent.toUri(0))
29+
+ " " + getResources().getText(R.string.hello_world3));
30+
31+
Toast.makeText(
32+
this,
33+
" PluginTestService "
34+
+ (intent == null ? " null" : (getResources().getText(R.string.hello_world3) + ", " + intent
35+
.toUri(0))), Toast.LENGTH_LONG).show();
36+
3537
return super.onStartCommand(intent, flags, startId);
3638
}
37-
39+
3840
@Override
3941
public IBinder onBind(Intent intent) {
4042
return null;
4143
}
42-
44+
4345
/**
4446
* 为了能在Service中正常访问插件中的资源。
4547
*/
4648
@Override
4749
protected void attachBaseContext(Context newBase) {
4850
super.attachBaseContext(PluginLoader.getDefaultPluginContext(PluginTestService.class));
4951
}
50-
52+
5153
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.example.plugintest.service;
2+
3+
import com.example.plugintest.R;
4+
import com.plugin.core.PluginLoader;
5+
6+
import android.app.Service;
7+
import android.content.Context;
8+
import android.content.Intent;
9+
import android.os.IBinder;
10+
import android.util.Log;
11+
import android.widget.Toast;
12+
13+
/**
14+
* @author cailiming
15+
*
16+
*/
17+
public class PluginTestService2 extends Service {
18+
19+
@Override
20+
public void onCreate() {
21+
super.onCreate();
22+
Log.d("PluginTestService2", "PluginTestService2 onCreate2");
23+
}
24+
25+
@Override
26+
public int onStartCommand(Intent intent, int flags, int startId) {
27+
28+
Log.d("PluginTestService2", "PluginTestService2 onStartCommand2 "
29+
+ (intent == null ? " null" : intent.toUri(0)) + " " + getResources().getText(R.string.hello_world3));
30+
31+
Toast.makeText(
32+
this,
33+
" PluginTestService2 "
34+
+ (intent == null ? " null" : (getResources().getText(R.string.hello_world3) + "," + intent
35+
.toUri(0))), Toast.LENGTH_LONG).show();
36+
37+
return super.onStartCommand(intent, flags, startId);
38+
}
39+
40+
@Override
41+
public IBinder onBind(Intent intent) {
42+
return null;
43+
}
44+
45+
/**
46+
* 为了能在Service中正常访问插件中的资源。
47+
*/
48+
@Override
49+
protected void attachBaseContext(Context newBase) {
50+
super.attachBaseContext(PluginLoader.getDefaultPluginContext(PluginTestService2.class));
51+
}
52+
53+
}

0 commit comments

Comments
 (0)