title: How to run an app in the background programmatically?
body: <p>I have this app that I am developing that is connected to a board. If the board detects falls, the app calls a number set by the user. However, the app only works when it is open. I want the app to run in the background so that even if the user is casually browsing through the web or doing something else, if a fall occurs, the app is able to perform the calling function.
  Below I have added the piece of code that performs the above said calling function. </p>
  
  <p>@Override</p>
  
  <pre><code>public int onStartCommand(Intent intent, int flags, int startId) {
  public void displayEvent(@AccelerationEvent int event, int data)
      {
          if (mCurrentDetectEvent == FeatureAccelerationEvent.DetectableEvent.FREE_FALL) {
              Context context = getContext();
              mShakeImage.start();
              button.setOnClickListener(v -&gt; {
                  Intent intent = new Intent(context, MainActivity.class);
                  context.startActivity(intent);
                  System.exit(0);
              });
  
              new Handler().postDelayed(() -&gt; {
                  new AlertDialog.Builder(context)
                          .setTitle("Alert")
                          .setMessage("This is an alert")
                          .show();
                  //---------------call function from CallScreen()------------------------------------
                  Intent intent = new Intent(context.getApplicationContext(), CallScreen.class);
                  context.startActivity(intent);
              }, 10000);
  
          }
  </code></pre>