|
楼主 |
发表于 2020-4-23 09:26:07
|
显示全部楼层
service app 的 manifest 部分如下
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<service
android:name=".MyService"
android:process=":remote"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.example.t_service.MyService"/>
<!--category android:name="android.intent.category.LAUNCHER" / !-->
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
客户app 中用显示的 intent 方法
Intent intent = new Intent();
intent.setClassName("com.example.t_service","com.example.t_service.MyService");
startService(intent); 和 bindService(intent, mConnection, Context.BIND_AUTO_CREATE); 都试了没用
但是换成
intent.setClassName("com.example.t_service","com.example.t_service.MainActivity");
startActivity(intent); 可以打开service app 的 atcivity
service app 的 manifest中 service 节中
android:process=":remote"
<intent-filter>
<action android:name="com.example.t_service.MyService"/>
<!--category android:name="android.intent.category.LAUNCHER" / !-->
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
是用来测式的,有或没有都不行。但用service app中的activity 则没有问题。不管activity 与 service 是不是在同一个进程中(即android:process=":remote" 是否设置) |
|