Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Toast message every 1 minute
    primarykey
    data
    text
    <p>I am trying to implement a service in Android that displays a toast message every 1 minute in Android. I am new to Android development and learned about AlarmManager that will help me do this. I have implemented the code in the following way:</p> <p>This is my IIManagerActivity class</p> <pre><code>package com.example.iimanager; import android.app.Activity; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.SystemClock; import android.view.Menu; import android.widget.Toast; public class IIManagerActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_iimanager); AlarmManager mgr=(AlarmManager)getSystemService(Context.ALARM_SERVICE); Intent i=new Intent(this, SampleService.class); PendingIntent pi=PendingIntent.getService(this, 0, i, 0); mgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), AlarmManager.INTERVAL_FIFTEEN_MINUTES/900, pi); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_iimanager, menu); return true; } } </code></pre> <p>And this is my SampleService that is meant to display a toast message. For some reason I cannot get to see a toast message no matter how long I wait.</p> <pre><code>package com.example.iimanager; import android.app.IntentService; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.widget.Toast; public class SampleService extends IntentService { public SampleService() { super("SimpleService"); //Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)", Toast.LENGTH_LONG).show(); } @Override protected void onHandleIntent(Intent intent) { //do something Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)", Toast.LENGTH_LONG).show(); } } </code></pre> <p>Can you please tell me what's wrong and what needs to be done to get it corrected?</p> <p>Thank you very much in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload