Note that there are some explanatory texts on larger screens.

plurals
  1. POMainActivity fails on phone
    text
    copied!<p>I'm doing a very simple example where I want a button to generate a notification. I'm not looking for interactivity (so no Intent); just that a simple notification should be published. The UI contains just a single button, which is clicked to generate the notification. </p> <p>Here's the code:</p> <pre><code>package ank.notificationdemo; import android.R.drawable; import android.os.Bundle; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { Button btn_notify; Notification noti; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn_notify = (Button) findViewById(R.id.btn_notify); noti = new Notification.Builder(MainActivity.this) .setContentTitle("Alert!").setContentText("Shipwreck at 22N-56E. Hurry!").setSmallIcon(drawable.ic_dialog_alert) .build(); btn_notify.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); noti.flags |= Notification.FLAG_AUTO_CANCEL; mgr.notify(100, noti); } }); } } </code></pre> <p>The problem is that this works on the Emulator, but the main activity fails to load on my Android phone (running ICS). Other examples have, however, worked fine.</p> <p>Any clue as to what might be going wrong?</p> <p>Thanks in advance!</p>
 

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