Notification Activity : Activity « UI « Android






Notification Activity

     
package app.test;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class Test extends Activity implements View.OnClickListener {
 
    private static final int NOTE_ID = 100;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Button button = new Button(this);
        button.setText("Post New Notification");
        button.setOnClickListener(this);
        setContentView(button);
    }
    @Override
    public void onClick(View v) {
        handler.postDelayed(task, 10000);
        Toast.makeText(this, "Notification will post in 10 seconds", Toast.LENGTH_SHORT).show();
    }
    
    private Handler handler = new Handler();
    private Runnable task = new Runnable() {
        @Override
        public void run() {
            NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
            Intent launchIntent = new Intent(getApplicationContext(), Test.class);
            PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, launchIntent, 0);
            
            Notification note = new Notification(R.drawable.icon, "Something Happened", System.currentTimeMillis());
            note.setLatestEventInfo(getApplicationContext(), "Finished!", "Click Here!", contentIntent);
            note.defaults |= Notification.DEFAULT_SOUND;
            note.flags |= Notification.FLAG_AUTO_CANCEL;
            
            manager.notify(NOTE_ID, note);
        }
    };
}

   
    
    
    
    
  








Related examples in the same category

1.Backup Activity
2.Timing Activity
3.Set content view from xml for Activity
4.More than one Activity
5.Find user control by using findViewById
6.A Simple Form
7.Link form with POJO
8.Life cycle
9.Comparing Android UI Elements to Swing UI Elements
10.add android:background = "#FFFF0000"
11.Rotation demo
12.Set activity screen Orientation
13.Check activity result
14.Activity lifecycle event
15.Activity key event
16.Allows the activity to manage the Cursor's lifecyle based on the activity’s lifecycle---
17.Activity configuration changed event
18.Check Activity result and onActivityResult
19.Phone Call Activity
20.Using Media Store Activity
21.External Storage Activity
22.Making Activity Go Full-Screen
23.Surface View Test Activity
24.Widget Preview Activity
25.This class provides a basic demonstration of how to write an Android activity.
26.This demonstrates the basic code needed to write a Screen activity
27.Example of removing yourself from the history stack after forwarding to another activity.
28.Fancy Blur Activity
29.Example of receiving a result from another activity.
30.Demonstrates required behavior of saving and restoring dynamic activity state
31.Securer Activity
32.This activity is an example of a simple settings screen that has default values.
33.Bind Click Action Activity
34.get ActivityManager
35.forward to another Activity
36.Request window features before setContentView
37.No code required here to attach the listener
38.Save data to Preference
39.Save instance state
40.onRetainNonConfigurationInstance
41.Create a user interface in code.
42.Redirect
43.Demonstrates how the various soft input modes impact window resizing.
44.extends Activity implements OnClickListener