title: Android activity is running twice
body: <p>I was running my application on a nexus 7 2013 and in logcat I noticed some logs running twice. After writing few more logs I concluded that every activity was running twice on tablet. The strange think is that on phone ( LG G3 or Samsung galaxy s4 mini ) logs are printed only 1 time.</p>
  
  <p>After doing some research I have tried to add <code>android:launchMode="singleTop"</code> or <code>singleTask</code> or <code>singleInstance</code> but none worked. Also I have some intents in activities with the flag:                 <code>intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);</code> and 2 <code>AsyncTasks</code>.</p>
  
  <p>Is there a way that the intents or the asynctask cause the problem ?</p>
  
  <p>Manifest:</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.example.marian.digimusicstream" &gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
      &lt;!--
       To retrieve OAuth 2.0 tokens or invalidate tokens to disconnect a user. This disconnect
       option is required to comply with the Google+ Sign-In developer policies
      --&gt;
      &lt;uses-permission android:name="android.permission.USE_CREDENTIALS" /&gt; &lt;!-- To retrieve the account name (email) as part of sign-in: --&gt;
      &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt; &lt;!-- To auto-complete the email text field in the login form with the user's emails --&gt;
      &lt;uses-permission android:name="android.permission.READ_PROFILE" /&gt;
      &lt;uses-permission android:name="android.permission.READ_CONTACTS" /&gt;
  
      &lt;permission android:name="android.permission.MEDIA_CONTENT_CONTROL" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppBaseTheme"&gt;
          &lt;activity
              android:name=".LoginActivity"
              android:label="@string/app_name"
              android:theme="@android:style/Theme.Light.NoTitleBar"
              android:windowSoftInputMode="stateHidden"
              android:launchMode="singleTop"&gt;
  
              &lt;!-- &lt;intent-filter&gt; --&gt;
              &lt;!-- &lt;action android:name="android.intent.action.MAIN" /&gt; --&gt;
              &lt;!-- &lt;category android:name="android.intent.category.LAUNCHER" /&gt; --&gt;
              &lt;!-- &lt;/intent-filter&gt; --&gt;
          &lt;/activity&gt;
  
          &lt;meta-data
              android:name="com.google.android.gms.version"
              android:value="@integer/google_play_services_version" /&gt;
  
          &lt;activity
              android:name=".musicPlayer"
              android:label="@string/title_activity_music_player"&gt;
  
              &lt;!-- android:theme="@android:style/Theme.DeviceDefault.Light.DarkActionBar" --&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;service android:name=".PlayerService" /&gt;
          &lt;service android:name=".audioService" /&gt;
  
          &lt;receiver android:name=".PlayPauseReceiver" /&gt;
          &lt;receiver android:name=".NetworkChangeReceiver" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.net.conn.CONNECTIVITY_CHANGE" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          &lt;receiver android:name=".musicPlayer$MusicNoisyReceiver" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.media.AUDIO_BECOMING_NOISY" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  
          &lt;activity
              android:name=".singleMusicScreen"
              android:label="@string/title_activity_single_music_screen" &gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Activity:</p>
  
  <pre><code>public class musicPlayer extends DrawerActivity {
  
      @Override
      protected void onCreate(final Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_music_player);
  
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
          mainLayout = (RelativeLayout) findViewById(R.id.mainLayout);
          pullToRefresh = (PullRefreshLayout) findViewById(R.id.pullToReresh);
          musicListLayout = new RelativeLayout(getApplicationContext());
  
          progressBar = new ProgressBar(getApplicationContext());
  
          pref = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);
          editor = pref.edit();
  
          getUser = pref.getString("sharedUser", "");
          getPassword = pref.getString("sharedPass", "");
  
          new doLogin().execute();
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_music_player, menu);
          return true;
      }
  
      @Override
      public void onBackPressed() {
          // Do Here what ever you want do on back press;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  
      public boolean isFirstItemCompletelyVisible() {
          return mLayoutManager.findFirstCompletelyVisibleItemPosition() == 0;
      }
  
      @Override
      public void onResume() {
          super.onResume();
          musicList.post(new Runnable() {
              @Override
              public void run() {
                  pullToRefresh.setEnabled(isFirstItemCompletelyVisible());
              }
          });
      }
  
      private class doLogin extends AsyncTask&lt;Void, Void, Boolean&gt; {
  
          @Override
          protected void onPreExecute() {
  
              Intent myIntent = getIntent();
              boolean button = myIntent.getBooleanExtra("LoginButton", false);
  
              if (!pref.getBoolean("isCheckBoxChecked", false) &amp;&amp; !button) {
                  Intent intent = new Intent(musicPlayer.this, LoginActivity.class);
                  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  getApplicationContext().startActivity(intent);
                  finish();
                  cancel(true);
              }
  
              if (button) {
                  getUser = myIntent.getStringExtra("userLogin");
                  getPassword = myIntent.getStringExtra("passLogin");
              }
  
              Log.i("TEST", "User: " + getUser + " pass: " + getPassword);
          }
  
          @Override
          protected Boolean doInBackground(Void... params) {
              try {
                  Log.i("TEST", "Init");
  
                  api = DefaultClientFactory.create(host, getUser, getPassword);
                  Log.i("TEST", "" + api.getUserInfo());
  
                  return true;
              } catch (StorageApiException e) {
                  e.printStackTrace();
                  return false;
              }
          }
  
          @Override
          protected void onPostExecute(Boolean result) {
              super.onPostExecute(result);
  
              if (!result) {
                  Intent intent = new Intent(musicPlayer.this, LoginActivity.class);
                  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  getApplicationContext().startActivity(intent);
                  Toast.makeText(getApplicationContext(), "Invalid E-mail or Password !", Toast.LENGTH_SHORT).show();
              } else {
  //                new backgroundTask().execute();
              }
  
          }
      }
  }
  </code></pre>