title: android broadcast receiver & notification
body: <p>hi the below code is the receiver class</p>
  
  <pre><code>import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.util.Log;
  
  
  public class AlarmReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          Log.e("the time is right","yay!");
          Intent i = new Intent(context.getApplicationContext() , AlarmServie.class);
          context.startService(i);
      }
  }
  </code></pre>
  
  <p>the below code is my service class</p>
  
  <pre><code>import android.app.NotificationManager;
  import android.app.PendingIntent;
  import android.app.Service;
  import android.content.Intent;
  import android.os.IBinder;
  import android.support.annotation.Nullable;
  import android.support.v4.app.NotificationCompat;
  import android.support.v4.app.TaskStackBuilder;
  import android.util.Log;
  
  public class AlarmServie extends Service {
      @Nullable
      @Override
      public IBinder onBind(Intent intent) {
          Log.e("hello","hi" );
          return null;
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
      super.onStartCommand(intent, flags, startId);
          Log.e("onCreate:","came" );
       /*  NotificationManager notifyman = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
          Intent main_activity = new Intent(this.getApplicationContext(), MainActivity.class);
          PendingIntent o = PendingIntent.getActivity(this, 0, main_activity, 0);
  
          /*Notification noti = new Notification.Builder(this)
                  .setContentTitle("Reminder to Pill")
                  .setContentText("Click for info")
                  .setAutoCancel(true)
                  .setContentIntent(o)v
                  .build();*/
          NotificationManager nm = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
          Intent in = new Intent(this.getApplicationContext(), MainActivity.class);
          PendingIntent pending = PendingIntent.getActivity(this, 0, in, 0);
          NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(AlarmServie.this);
          mBuilder.setContentTitle("Pill Reminder");
          mBuilder.setContentText("CLick here to View");
          //mBuilder.setSound(sound);
  
          TaskStackBuilder ts=TaskStackBuilder.create(this);
          ts.addParentStack(MainActivity.class);
          nm.notify(9999,mBuilder.build());
          return START_STICKY;
      }}
  </code></pre>
  
  <p>the below code is my manifest</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.VIBRATE"/&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK"/&gt;
      &lt;uses-permission android:name="com.android.alarm.permission.SET_ALARM"/&gt;
      &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/&gt;
  
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name"
              android:theme="@style/AppTheme.NoActionBar"&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;receiver
                    android:name=".AlarmReceiver"
                    android:enabled="true"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.BOOT_COMPLETED"/&gt;
              &lt;/intent-filter&gt;
  
          &lt;/receiver&gt;
  
          &lt;activity android:name=".Set"&gt;
  
          &lt;/activity&gt;&lt;!-- ATTENTION: This was auto-generated to add Google Play services to your project for
       App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information. --&gt;
          &lt;meta-data
              android:name="com.google.android.gms.version"
              android:value="@integer/google_play_services_version" /&gt;
  
  
              &lt;service
                  android:name=".AlarmServie"
                  android:enabled="true"/&gt;
  
  
  
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>i used a textbox and a timer button to get text and time from user and saved it in database.when the time in db and system time matches notification must come but it is not coming can anyone say why this happens.clearly explain y this happens by explaining in detail with code  </p>
  
  <p>this is my main activity</p>
  
  <pre><code>import android.app.AlarmManager;
  import android.app.PendingIntent;
  import android.content.Context;
  import android.content.Intent;
  import android.database.Cursor;
  import android.os.Bundle;
  import android.support.design.widget.FloatingActionButton;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.ListView;
  import android.widget.TextView;
  
  import com.google.android.gms.common.api.GoogleApiClient;
  
  import java.util.ArrayList;
  import java.util.Calendar;
  import java.util.Date;
  import java.util.List;
  
  
  public class MainActivity extends AppCompatActivity {
      Sqlitedb dbobj1;
      int gh;
      AlarmManager am;
  
  
      Calendar c;
      /**
       * ATTENTION: This was auto-generated to implement the App Indexing API.
       * See https://g.co/AppIndexing/AndroidStudio for more information.
       */
      private GoogleApiClient client;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
          dbobj1 = new Sqlitedb(MainActivity.this);
          gh = (int) dbobj1.number();
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          Calendar c = Calendar.getInstance();
  
          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Intent intent = new Intent(MainActivity.this, Set.class);
                  startActivity(intent);
              }
          });
          Intent my_intent = new Intent(MainActivity.this, AlarmServie.class);
  
  
          am = (AlarmManager) getSystemService(ALARM_SERVICE);
          Date dt = new Date();
          int hour=dt.getHours();
          int min=dt.getMinutes();
          PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 0, my_intent, PendingIntent.FLAG_UPDATE_CURRENT);
          Cursor t = dbobj1.recenttime(hour,min);
          t.moveToFirst();
          c.set(Calendar.HOUR_OF_DAY, t.getInt(0));
          c.set(Calendar.MINUTE, t.getInt(1));
          am.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pi);
  
  
          populate();
  
      }
          // ATTENTION: This was auto-generated to implement the App Indexing API.
          // See https://g.co/AppIndexing/AndroidStudio for more information.
          //client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
      //oncreate ends here
  
  
      class customAdabter extends ArrayAdapter&lt;setget&gt; {
          Context _context;
          List&lt;setget&gt; _li;
  
          public customAdabter(Context con, int layout, List&lt;setget&gt; li) {
              super(con, layout, li);
              _context = con;
              _li = li;
          }
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              gh++;
              LayoutInflater layu = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
              View v = layu.inflate(R.layout.item, null);
  
  
              TextView txt = (TextView) v.findViewById(R.id.item_textview1);
              TextView txt1 = (TextView) v.findViewById(R.id.item_textview2);
              Button btt = (Button) v.findViewById(R.id.item_button1);
              btt.setId(gh);
  
              btt.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
  
                      int r = v.getId();
                      dbobj1.deleteRow(r);
  
                      populate();
  
                  }
              });
  
              setget dataobj = _li.get(position);
  
              txt.setText(dataobj.getPn());
              txt1.setText(dataobj.getPt());
  
              return v;
          }
      }
  
  
      public void populate() {
          List&lt;setget&gt; li = new ArrayList&lt;setget&gt;();
  
          for (int i = 1; i &lt;= dbobj1.number(); i++) {
              setget obj = new setget();
              Cursor c = dbobj1.getRow(i);
              String name = c.getString(c.getColumnIndex("pillname"));
              String time = c.getString(c.getColumnIndex("pilltime"));
              obj.setPn(name);
              obj.setPt(time);
              c.close();
              li.add(obj);
          }
          ListView lv = (ListView) findViewById(R.id.listview);
          customAdabter customobj = new customAdabter(MainActivity.this, R.layout.item, li);
          lv.setAdapter(customobj);
  
      }
  }
  </code></pre>
  
  <p>this is the logcat </p>
  
  <pre><code>09-19 11:30:32.267 19426-19426/com.example.ashwin.pillreminder11 D/ActivityThread: BDC-Calling onReceive: intent=Intent { flg=0x114 cmp=com.example.ashwin.pillreminder11/.AlarmReceiver (has extras) }, receiver=com.example.ashwin.pillreminder11.AlarmReceiver@d5ea50b
  
  09-19 11:30:32.267 19426-19426/com.example.ashwin.pillreminder11 E/the time is right: yay!
  
  09-19 11:30:32.268 19426-19426/com.example.ashwin.pillreminder11 D/ActivityThread: BDC-RECEIVER handled : 0 / ReceiverData{intent=Intent { flg=0x114 cmp=com.example.ashwin.pillreminder11/.AlarmReceiver (has extras) } packageName=com.example.ashwin.pillreminder11 resultCode=0 resultData=null resultExtras=null}
  </code></pre>