0

I am trying to open an activity and a service together. I am using Android Studio 2.3.3. I have created an empty activity for the Phone and Tablet, API 14. I was able to open the activity which popped up the activity Hello World. I created another empty activity and it contains a print service. I am able to open the activity and service separately. When I add the service to the activity, the activity open but the service does not. Here is the manifest file for the activity:

 <?xml version="1.0" encoding="utf-8"?>
   <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.android.testactivity">

        <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">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>

    </manifest>

Here is the manifest for the service:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.testprintservice">

    <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="com.example.android.testprintservice.TestPrintService"

            android:permission="android.permission.BIND_PRINT_SERVICE">
            <intent-filter>
                <action android:name="android.printservice.PrintService"/>
            </intent-filter>
            <meta-data
                android:name="android.printservice"
                android:resource="@xml/test_printservice">
            </meta-data>
        </service>
    </application>
</manifest>
droidev
  • 7,352
  • 11
  • 62
  • 94
Jeff
  • 19
  • 1
  • 2
  • Why do you use two different application? Can you have your service in the same application that you have your activity? I guess you are implementing your idea in a wrong way. Can you please explain what you need? To clarify my point: you can have one application in which you will have an activity which will statrt a service when it runs. On the other hand, if you really need s separate activity to start a service in another application, you should use broadcast. Send a broascast in first application when activity statrs and add receiver in second activity to listen to this broadcast. – Akram Jun 21 '17 at 05:24
  • I have an application that converts documents to pdf and I have a print service. I want to install both items at the same time as part of the application. – Jeff Jun 21 '17 at 19:13
  • Refer to this link for how I solved the issue: https://stackoverflow.com/questions/44661014/installing-multiple-android-apps-with-1-apk?noredirect=1#comment76312899_44661014 – Jeff Jun 22 '17 at 00:55

0 Answers0