Guest User

Untitled

a guest
Feb 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. startService.setOnClickListener(new View.OnClickListener() {
  2. @Override
  3. public void onClick(View view) {
  4. Log.d("myE", "Start click");
  5. try
  6. {
  7. Context ctx = (Context)MonitoringFragment.this.getActivity();
  8. ctx.startService(new Intent(getContext(), CheckService.class));
  9. }
  10. catch (Exception e)
  11. Log.d("myE", e.toString());
  12. Log.d("myE", "End click");
  13. }
  14. }
  15.  
  16. public class CheckService extends Service
  17. {
  18. @Nullable
  19. @Override
  20. public IBinder onBind(Intent intent) {
  21. return null;
  22. }
  23.  
  24. public int onStartCommand(Intent intent, int flags, int startId) {
  25. try {
  26. Log.d("myE", "onStartCommand");
  27. }
  28. catch (Exception e) {
  29. Log.d("myE", e.toString());
  30. }
  31. return START_STICKY;
  32. }
  33. }
  34.  
  35. <service android:name=".MonitoringFragment$CheckService" />
Add Comment
Please, Sign In to add comment