title: How to resume Android Activity programmatically from background
body: <p>Situation:</p>
  
  <ol>
  <li>Let's say I have currently working launched application Activity A.</li>
  <li>After some time I am pressing "Home" button. Application A goes to background.</li>
  <li>At this time, I am starting to use another app B - youtube for example or etc.</li>
  <li>Something happens (doesn't matter what in this context, let's say timer finished calculating time) in the application A which currently is minimized to background.</li>
  <li>On the event occurrence, application A activity automatically resumes from background.</li>
  </ol>
  
  <p>Question:</p>
  
  <p>How to accomplish step 5? Basically I need to know how to resume application from background programmatically.</p>
  
  <p>I tried to launch intent to "restart" my application activity but it didn't worked:</p>
  
  <pre><code>Intent intent = new Intent(context, MainActivity.class);
              intent.setAction(Intent.ACTION_MAIN);
              intent.addCategory(Intent.CATEGORY_LAUNCHER);
              context.startActivity(intent);
  </code></pre>
  
  <p>My manifest file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.taxti"
      android:versionCode="43"
      android:versionName="1.5.3" &gt;     
  
      &lt;uses-sdk
          android:minSdkVersion="13"
          android:targetSdkVersion="21" /&gt;
  
      &lt;permission
          android:name="com.example.taxti.permission.MAPS_RECEIVE"
          android:protectionLevel="signature" /&gt;
  
      &lt;uses-feature
          android:glEsVersion="0x00020000"
          android:required="true" /&gt;
  
      &lt;uses-permission android:name="com.example.taxti.permission.MAPS_RECEIVE" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
      &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;       
      &lt;permission android:name="com.taxti.permission.C2D_MESSAGE"
                  android:protectionLevel="signature" /&gt;
      &lt;uses-permission android:name="com.taxti.permission.C2D_MESSAGE" /&gt;     
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;   
      &lt;uses-permission android:name="android.permission.CALL_PHONE" /&gt;  
      &lt;uses-permission android:name="android.permission.EXPAND_STATUS_BAR" /&gt;
      &lt;uses-permission android:name="android.permission.CLEAR_APP_CACHE" /&gt;
  
      &lt;application
          android:allowBackup="true"        
          android:icon="@drawable/ic_launcher"
          android:hardwareAccelerated="true"
          android:label="@string/app_name"
          android:name="com.taxti.Globals"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name="com.taxti.InitialActivity"
              android:label="@string/app_name"
              android:windowSoftInputMode="adjustPan"
              android:screenOrientation="sensorLandscape"
              android:theme="@style/MyTheme" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name="com.taxti.MainActivity"
              android:label="@string/app_name"
              android:launchMode="singleTop"
              android:windowSoftInputMode="adjustPan"
              android:screenOrientation="sensorLandscape"
              android:theme="@style/MyTheme"&gt;
          &lt;/activity&gt;
  
          &lt;service android:name=".MainActivityForegroundService" /&gt;
  
          &lt;intent-filter&gt;
                  &lt;action android:name="android.net`enter code here`.conn.CONNECTIVITY_CHANGE" /&gt;                
          &lt;/intent-filter&gt;
  
         &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.CALL_PRIVILEGED" /&gt;
              &lt;category android:name="android.intent.category.DEFAULT" /&gt;     
              &lt;action android:name="android.intent.action.DIAL" /&gt;
              &lt;action android:name="android.intent.action.CALL_BUTTON" /&gt;     
              &lt;category android:name="android.intent.category.BROWSABLE" /&gt;           
              &lt;data android:scheme="tel" /&gt;
         &lt;/intent-filter&gt;
  
          &lt;meta-data
              android:name="com.google.android.gms.version"
              android:value="@integer/google_play_services_version" /&gt;
          &lt;meta-data
              android:name="com.google.android.maps.v2.API_KEY"
              android:value="xxxx" /&gt;             
          &lt;uses-library android:name="com.google.android.maps" /&gt;
  
          &lt;receiver
              android:name=".GcmBroadcastReceiver"
              android:permission="com.google.android.c2dm.permission.SEND" &gt;   
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;               
                  &lt;category android:name="com.taxti" /&gt;
              &lt;/intent-filter&gt;
  
          &lt;/receiver&gt;
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>