@Override
 protected void onResume() {
   // TODO Auto-generated method stub
   super.onResume();
   if (NFCAdapter != null)
     NFCAdapter.enableForegroundDispatch(this, pendingIntent, i, techListsArray);
 }
 @Override
 protected void onNewIntent(Intent intent) {
   // TODO Auto-generated method stub
   super.onNewIntent(intent);
   // after detecting tag..
   ScanTag(intent);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // creating pending intent
    pendingIntent =
        PendingIntent.getActivity(
            this,
            0,
            new Intent(getApplicationContext(), this.getClass())
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY),
            0);

    i[0] = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    // creating tech list for tag
    techListsArray =
        new String[][] {
          new String[] {
            NfcV.class.getName(),
            NfcA.class.getName(),
            NfcB.class.getName(),
            NfcF.class.getName(),
            Ndef.class.getName(),
            NdefFormatable.class.getName(),
            MifareClassic.class.getName(),
            MifareUltralight.class.getName()
          }
        };

    // creating object of nfc adapter of mobile device
    NFCAdapter = NfcAdapter.getDefaultAdapter(this);

    // if app is opened after pop up....
    ScanTag(getIntent());
  }
 @Override
 protected void onPause() {
   // TODO Auto-generated method stub
   super.onPause();
   if (NFCAdapter != null) NFCAdapter.disableForegroundDispatch(this);
 }
 @Override
 protected void onDestroy() {
   // TODO Auto-generated method stub
   super.onDestroy();
   finish();
 }