安卓:stopService在另一个活动 [英] Android: stopService in another Activity

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

问题描述

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

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.

推荐答案

您应该调用<一个href=\"http://developer.android.com/reference/android/content/ContextWrapper.html#stopService%28android.content.Intent%29\"><$c$c>Activity(ContextWrapper)#stopService:

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

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

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