Advertisement
Guest User

StatusCheckStarter.java

a guest
Nov 8th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. package com.your.example;
  2.  
  3. import android.content.BroadcastReceiver;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.widget.Toast;
  7. import android.util.Log; // Add this line
  8.  
  9. public final class StatusCheckStarter extends BroadcastReceiver {
  10. static Context myActivity;
  11. private static StatusCheckStarter instance;
  12. public static String text = "hello world";
  13.  
  14. public static void makeToast() {
  15. Toast.makeText(myActivity, text, Toast.LENGTH_LONG).show();
  16. }
  17.  
  18. public static void receiveActivityInstance(Context tempActivity) {
  19. myActivity = tempActivity;
  20. Log.d("StatusCheckStarter", "Activity reference received.");
  21. }
  22.  
  23. public static void StartCheckerService() {
  24. Log.d("StatusCheckStarter", "Attempting to start LocationPlugin service.");
  25. myActivity.startService(new Intent(myActivity, LocationPlugin.class));
  26. }
  27.  
  28. public static void StopCheckerService() {
  29. Log.d("StatusCheckStarter", "Stopping LocationPlugin service.");
  30. myActivity.stopService(new Intent(myActivity, LocationPlugin.class));
  31. }
  32.  
  33.  
  34.  
  35. @Override
  36. public void onReceive(Context context, Intent intent) {
  37. Log.d("StatusCheckStarter", "Broadcast received."); // Log statement added
  38. String sentIntent = intent.getStringExtra(Intent.EXTRA_TEXT);
  39. if (sentIntent != null) {
  40. text = sentIntent;
  41. Toast.makeText(myActivity, "Received number: " + sentIntent, Toast.LENGTH_LONG).show();
  42. }
  43. }
  44.  
  45.  
  46. public static void createInstance() {
  47. if (instance == null) {
  48. instance = new StatusCheckStarter();
  49. }
  50. }
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement