停止服务,这是活动的内部类

时间:2016-04-09 08:44:53

标签: java android

我正在尝试像app这样的截屏视频。我每隔几秒就截取一次屏幕截图。我将广播发送到当前显示的ActivityonReceive我呼叫方法以获取屏幕截图。 Service是我从Activity调用的类的内部类,用于启动服务。

我启动了在活动的onCreate中发送广播的服务并将其停止onPause我想知道当前显示的是哪个活动,所以我将一个字符串发送给该类的构造函数{ {1}}用于了解将广播发送到哪个活动。

我只想知道如何从活动中停止一个内部类的服务。

带有服务的内部类:

Service

活动中的public class InnerServiceClass { static String activityName; InnerServiceClass(String activityName){ this.activityName = activityName; } // UNREGISTER RECEIVER public static class SShotService extends Service{ Intent intent; private static final String TAG = "BroadcastService"; public static final String BROADCAST_ACTION = "com.websmithing.broadcasttest.displayevent"; private final Handler handler = new Handler(); ArrayList objects = new ArrayList(); @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); intent = new Intent(BROADCAST_ACTION); Toast.makeText(getApplicationContext(), "serv", Toast.LENGTH_LONG).show(); } @Override public void onStart(Intent intent, int startId) { handler.removeCallbacks(sendUpdatesToUI); handler.postDelayed(sendUpdatesToUI, 1000); } private Runnable sendUpdatesToUI = new Runnable() { public void run() { DisplayLoggingInfo(); handler.postDelayed(this, 2000); // 5 seconds } }; private void DisplayLoggingInfo() { Log.d(TAG, "entered DisplayLoggingInfo"); intent.putExtra("extra", activityName); sendBroadcast(intent); } } }

onReceive

0 个答案:

没有答案
相关问题