Android Programming Tutorials

(Romina) #1
A Subtle Notification

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

status=(EditText)findViewById(R.id.status);

Button send=(Button)findViewById(R.id.send);

send.setOnClickListener(onSend);

prefs=PreferenceManager.getDefaultSharedPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(prefListener);

bindService(new Intent(this, PostMonitor.class), svcConn,
BIND_AUTO_CREATE);

adapter=new TimelineAdapter();
((ListView)findViewById(R.id.timeline)).setAdapter(adapter);

clearNotification();
}

If you try this, it will work...if Patchy had been closed. If, however, Patchy


were open, and you click on the event, the icon would remain intact.


The reason is that if Patchy were open, the currently-running Patchy is being


brought to the foreground. Since a new Patchy instance is not being


created, onCreate() does not get called.


However, in this case, a separate callback method, onNewIntent(), will be


called. So, override onNewIntent() in Patchy and call clearNotification()


from there:


@Override
public void onNewIntent(Intent i) {
super.onNewIntent(i);

clearNotification();
}

Now, the icon should go away even if Patchy were already running when


you click on the event.


224
Free download pdf