Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中从浏览器启动服务_Android_Android Service - Fatal编程技术网

在android中从浏览器启动服务

在android中从浏览器启动服务,android,android-service,Android,Android Service,每当点击浏览器中的链接时,我想启动一项服务。我从下面的意图过滤器中知道,我们可以启动活动 <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <cate

每当点击浏览器中的链接时,我想启动一项服务。我从下面的意图过滤器中知道,我们可以启动活动

         <intent-filter> 
             <action android:name="android.intent.action.VIEW" />

             <category android:name="android.intent.category.DEFAULT" />
             <category android:name="android.intent.category.BROWSABLE" /> 

            <data android:scheme="acb" /> 

            android:host="*.abc.com"
             android:scheme="http" /> 
             <data
            android:host="*.abc.com"
            android:scheme="http" />
          </intent-filter>

android:host=“*.abc.com”
android:scheme=“http”/>

您需要让链接启动启动服务的活动。您不能直接从链接启动服务。

问题是,当我启动新活动时,会创建两个应用程序外的实例,一个在后台运行,另一个是我启动的。@piyush:通常,一次只存在一个“应用程序外的实例”。唯一能改变这种情况的方法是,如果你做了一些不幸的事情,比如在清单中乱搞
android:process
属性。如果我的应用程序在后台运行,我想说的是,我点击浏览器链接,然后,当我在平板电脑中看到最近的应用程序列表时,我可以看到带有应用程序缩略图的浏览器,这就是创建两个实例的方式。@piyush:应用程序有一个实例,但它可能在两个任务中有活动。清单中有一些设置可用于帮助控制此操作,或者您可以在启动服务后简单地
finish()
活动。无论如何,正如我在回答中所写,您不能直接从链接启动服务。因此,要么使用启动服务的活动,要么放弃服务,要么放弃这种浏览器集成,要么停止编写应用程序。