【发布时间】:2019-12-27 16:03:57
【问题描述】:
我正在持续运行一个服务页面,我不需要使用活动或在我的设备中显示应用程序图标
除了主要活动之外,我还有一个扩展服务的 java 类,我在主类中评论了“setContentView”不是为了显示布局,但是当我运行应用程序时,我会得到一个空白页,是的,我的服务也运行
主Activity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
Intent serviceIntent = new Intent(this, MyServices.class);
startService(serviceIntent);
}
}
我希望我的应用程序不会在我的设备中显示或显示图标,而只是为了运行我的服务。
先谢谢了,请帮我解决这个问题。
【问题讨论】:
-
服务在您的应用关闭或打开时运行。那么你想达到什么目的呢?
-
你不能再在没有显示永久通知的情况下在 android 中这样做了。
-
@GauravMall 我不想让活动显示在我的设备中,而只是为了运行服务,难道不能通过其他方式吗?
-
好吧,这不再被允许了。 Android 会终止任何没有任何省电目的的服务。
-
可以运行后台服务,但如果您的活动未显示,则需要在托盘上显示永久通知。
标签: android android-studio android-activity service