Android:在另一个活动中停止服务 [英] Android: stopService in another Activity

查看:27
本文介绍了Android:在另一个活动中停止服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在另一个活动中停止我的服务?

How can I stop my Service in another Activity?

我在summaryActivity中启动服务

I start the service in my summaryActivity

SocketServiceIntent = new Intent(this, SocketService.class);
SocketServiceIntent.putExtra("MessageParcelable", mp);
startService(SocketServiceIntent);

并从我的 summaryActivity 开始我的 statusActivity

And start my statusActivity from my summaryActivity

Intent intent = new Intent(SummaryActivity.this,
                StatusActivity.class);
intent.putExtra("MessageParcelable", mp);
startActivity(intent);

我的问题是我不知道如何给我的 Statusactivity SocketServiceIntent.

My problem is that I don't know how I can give my Statusactivity the SocketServiceIntent.

推荐答案

你应该调用 Activity(ContextWrapper)#stopService:

You should call Activity(ContextWrapper)#stopService:

stopService(new Intent(SummaryActivity.this, SocketService.class));

这篇关于Android:在另一个活动中停止服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆