title: Without Button click How to call MyService class in MainActivity in android studio
body: <p>Without Button click How to call MyService class in MainActivity. My issue is to call MyService class in MainActivity class because when app start notification automatically started.</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          MyService my = new MyService();
      }
  }
  </code></pre>
  
  <p>MyService.Java</p>
  
  <pre><code>public class MyService extends Service {
      @Override
      public IBinder onBind(Intent arg0) {
          return null;
      }
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          showNotification();
          return START_STICKY;
      }
      @Override
      public void onDestroy() {
          super.onDestroy();
          Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
      }
      private void showNotification() {
          NotificationCompat.Builder mBuilder =
                  (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                          .setSmallIcon(R.drawable.ic_loc)
                          .setContentTitle("Welcome to Brillio")
                          .setContentText("Hello Mansur, Welcome to Brillio! You'll be shortly attended by Renji! ")
                          .setPriority(2)
                          .setOnlyAlertOnce(false);
          Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
          mBuilder.setSound(alarmSound);
  
          NotificationManager mNotificationManager =
                  (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
          mNotificationManager.notify(2001, mBuilder.build());
      }
  }
  </code></pre>