suppose I click start button and close the application but Notification is running. After five miutes I open notification then second activity opens and settext with 5 min.Again i close appliction.Then again I click on start button.suppose after 3 min i check notification it should open with 3 min not 8.but in my application it show 8 min
1:Main ACtivity where notification is start
public class MainActivity extends Activity {
final Context context=this;
private EditText timerValue;
private static final int NOTIFY_ME_ID=1337;
Intent MyIntent;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
timerValue = (EditText) findViewById(R.id.timerValue111);
startButton = (Button) findViewById(R.id.startButton);
x=timerValue.getText().toString();
nman=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
startButton.setOnClickListener(new View.OnClickListener() {
#TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void onClick(View view) {
Long s1=(long) 0.0;
String timeStamp = new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime());
//Toast.makeText(MainActivity.this,timeStamp,2000).show();
Date interestingDate = new Date();
s1= interestingDate.getTime();
int seconds = (int) (s1/ 1000) % 60 ;
int minutes = (int) ((s1 /(1000*60)) % 60);
int hours = (int) ((s1 /(1000*60*60)) % 24);
Toast.makeText(MainActivity.this,"Time:"+hours+":"+minutes+":"+seconds,2000).show();
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String MyText = "Reminder";
Notification mNotification = new Notification(R.drawable.ic_launcher, MyText, System.currentTimeMillis() );
//The three parameters are: 1. an icon, 2. a title, 3. time when the notification appears
String MyNotificationTitle = "Medicine!";
String MyNotificationText = "Don't forget to take your medicine!";
MyIntent = new Intent(MainActivity.this,SecondActivity.class);
MyIntent.putExtra("s1", (long)s1);
PendingIntent StartIntent = PendingIntent.getActivity(getApplicationContext(),0,MyIntent,0);
// x=timerValue.getText().toString();
//A PendingIntent will be fired when the notification is clicked. The FLAG_CANCEL_CURRENT flag cancels the pendingintent
mNotification.setLatestEventInfo(getApplicationContext(), MyNotificationTitle, MyNotificationText, StartIntent);
mNotification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, mNotification);
}
});
}
}
2:Second Activity where total time is calculated
public class SecondActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
long p=(long) 0.0;
long s=(long) 0.0;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
TextView text1=(TextView)findViewById(R.id.text1);
Bundle extras = getIntent().getExtras();
Date interestingDate = new Date();
s= interestingDate.getTime();
long x1=extras.getLong("s1");
p=s-x1;
int minutes = (int) ((p /(1000*60)) % 60);
text1.setText(""+minutes);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.second, menu);
return true;
}
}
That is happening maybe because you do not close the application, so the application goes in onPause state, and your second activity is not calling the onDestroy => when you enter again in the second activty, is called the onResume method, where you do not set the TextView text
Related
i am doing a notification view project. notification does appear on notification bar, when i click on notification bar it will go on next activity to display the same info that notification what has. but got an error this...
E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb96ae9c0
my code is
MainActivity.java
public class MainActivity extends AppCompatActivity {
Button view_notifi,btn_time,btn_date;
int notificationID,getHour,getMin,getDay,getMonth,getYear;
final int dialogTime=0,dialogDate=1;
Notification notification;
EditText edt_heading,edt_details,edt_details2;
String head,details,details2;
String Time,setDate;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edt_heading=(EditText)findViewById(R.id.editText_Heading);
edt_details=(EditText)findViewById(R.id.editText_Details);
edt_details2=(EditText)findViewById(R.id.editText_details2);
notificationID=1;
view_notifi=(Button)findViewById(R.id.button_viewN);
btn_time=(Button)findViewById(R.id.button_time);
btn_date=(Button)findViewById(R.id.button_date);
view_notifi.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
head=edt_heading.getText().toString();
details=edt_details.getText().toString();
details2=edt_details2.getText().toString();
displayNotification(head,details,details2);
edt_heading.getText().clear();
edt_details.getText().clear();
edt_details2.getText().clear();
}
});
}
public void getTimeInfo(View view){
showDialog(dialogTime);
}
public void getDateInfo(View view){
showDialog(dialogDate);
}
protected Dialog onCreateDialog(int id){
switch (id){
case dialogTime:
return new TimePickerDialog(this,mTimeListener,getHour,getMin,false);
case dialogDate:
DatePickerDialog dialog = new DatePickerDialog(this, mDateListener, getYear, getMonth, getDay);
DatePicker datePicker = dialog.getDatePicker();
Calendar calendar = Calendar.getInstance();
datePicker.setMinDate(calendar.getTimeInMillis());
//dialog.getDatePicker().setMinDate(new Date().getTime());
return dialog;
//return new DatePickerDialog(this,mDateListener,getYear,getMonth,getDay);
}
return null;
}
private TimePickerDialog.OnTimeSetListener mTimeListener=new TimePickerDialog.OnTimeSetListener(){
#Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
getHour=hourOfDay; getMin=minute;
Time=String.valueOf(" "+getHour+":"+getMin);
Toast.makeText(getBaseContext(),"Time: "+Time,Toast.LENGTH_SHORT).show();
}
};
private DatePickerDialog.OnDateSetListener mDateListener=new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
getYear=year; getMonth=monthOfYear+1;getDay=dayOfMonth;
//getMonth=+1;
setDate=String.valueOf(" "+getDay+"/"+getMonth+"/"+getYear);
Toast.makeText(getBaseContext(),"Date: "+setDate,Toast.LENGTH_SHORT).show();
}
};
public void displayNotification(String str1,String str2,String str3){
Intent intent = new Intent("notify_filter");
Bundle bundle = new Bundle();
bundle.putString("arg1", str1);
bundle.putString("arg2", str2);
bundle.putString("arg3", str3);
bundle.putString("arg4", Time);
bundle.putString("arg5", setDate);
intent.putExtras(bundle);
intent.putExtra("notificationID",notificationID);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification.Builder builder = new Notification.Builder(MainActivity.this);
builder.setAutoCancel(true);
builder.setTicker("New Alert...");
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setContentTitle(str1);
builder.setContentText(str2);
builder.setSubText("Time " + Time + " Date:" + setDate); //API level 16
builder.setContentIntent(pendingIntent);
builder.setOngoing(true);
builder.setNumber(100);
builder.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notification = builder.getNotification();
notification.vibrate = new long[]{100, 250, 100, 400};
notificationManager.notify(notificationID, notification);
}
}
ViewNotification.java
public class ViewNotification extends AppCompatActivity {
TextView head,detail1,detail2,time,date;
Bundle bundle;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_notification);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancel(getIntent().getExtras().getInt("notificationID"));
head=(TextView)findViewById(R.id.textView_head);
detail1=(TextView)findViewById(R.id.textView_det1);
detail2=(TextView)findViewById(R.id.textView_det2);
time=(TextView)findViewById(R.id.textView_time);
date=(TextView)findViewById(R.id.textView_date);
bundle = getIntent().getExtras();
String view1= bundle.getString("arg1");
String view2= bundle.getString("arg2");
String view3= bundle.getString("arg3");
//String view4=bundle.getString("arg4");
//String view5=bundle.getString("arg5");
head.setText(view1);
detail1.setText(view2);
detail2.setText(view3);
time.setText(bundle.getChar("arg4"));
date.setText(bundle.getChar("arg5"));
}
}
This happens when you try to set value of TextView to an integer.
When you assign a value of String to a TextView this error disappears.
For example
I have create a Text View in xml file. I am trying to set the value of that particular text field from java code. I am setting the int value to Text View but I am receiving an error getSlotFromBufferLocked: unknown buffer: 0xab7519c0 but after changing value from int to String and setting TextView from that String error disappears and app is working fine.
i have a project that use alarmmanager. many avtivity set alarms and then when alarm have been rise,specific activity in name of AlarmSetter that started show alarm and also set a new (next) alarm and snooz alarm(if user needs). my problem is just the last alarm setted . this mean all activity set alarm byut the last alarm set has worked .for example in alarm setter if user select snooz button then main alarm dont work(just snooz work as well = the last alarm sat).
i set alarmmanager in G class(common) and use and set alarm in activity alarm.java
This is My G Class :
public class G extends Application {
public static AlarmManager alarmManager;
#Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
}
}
Alarm Setter Java IS :
public class ActivityAlarm extends ActivityMain {
#Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.alarmshower);
//at first reminder will start, should register next alarm time :
long MilisectoAlarmManager = mDbHelper.SetNextTime_andIsactiveYET(DrugRegID);
if (MilisectoAlarmManager != 0 && IsFor10minlater == 0) {
Intent intentMain = new Intent(G.context, ActivityAlarm.class);
intentMain.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intentMain.putExtra("DrugID", String.valueOf(DrugRegID));
intentMain.putExtra("IsItFor10MinLate", String.valueOf(0));
PendingIntent pendingIntentMain = PendingIntent.getActivity(G.context, 0, intentMain, PendingIntent.FLAG_UPDATE_CURRENT);
String AA = mDbHelper.GetStartDateAlarm(DrugRegID);
Date D = new Date(MilisectoAlarmManager);
System.out.println("current Date(ms): " + MilisectoAlarmManager);
G.alarmManager.set(AlarmManager.RTC_WAKEUP, MilisectoAlarmManager, pendingIntentMain);
}
//Finished Activing Alarm Manager and switch Off Alarmn
else if (MilisectoAlarmManager == 0 && IsFor10minlater == 0) {
mDbHelper.UpdateAlarmSwitch(DrugRegID, false);
}
handler.postDelayed(r, HowLongRemainAlarm_var);
//End CountDown Finished Activity
//Procedure for 10 min later button
btn10minLater_var.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
btn10minLater_var.setBackgroundColor(Color.parseColor("#1174b9"));
Intent intentFor10min = new Intent(G.context, ActivityAlarm.class);
intentFor10min.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intentFor10min.putExtra("DrugID", String.valueOf(DrugRegID));
intentFor10min.putExtra("IsItFor10MinLate", String.valueOf(1));
PendingIntent pendingIntent10min = PendingIntent.getActivity(G.context, 0, intentFor10min, PendingIntent.FLAG_UPDATE_CURRENT);
G.alarmManager.set(AlarmManager.RTC_WAKEUP, new Date().getTime() + 20000, pendingIntent10min);
ActivityAlarm.this.finish();
}
});
i found asnwer ! in PendingIntent.getActivity secound parameter must have diffrent in each alarm set !
hi i have a problem with my code in the multiple alarm . i typed my code to be work on a multiple alarms every alarm take 10 seconds to be triggered REPEATEDLY. my problem that the alarm work with just one value but although i have put a different requestCode, but it cannot bet work or i don't know how i call every one separately .
the problem is i'v try to do this--->
alarm1 with a value and a request code 0 (for example) for 10 seconds
alarm2 with a different value and a request code 1 (for example) for 10 seconds
the code do this---->
desplay an just alarm2 that i selected lately
static int HELLO_ID = 1;
boolean flag = false;
int CountMultipleAlarm = 0;
EditText edt,edt2;
Button btn;
CountDownTimer timer;
//the strings of the notifications
String titlePills = "Time to take Panadol",DescriptionPills = "Panadol";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.planets_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
btn = (Button)findViewById(R.id.button1);
edt = (EditText)findViewById(R.id.editText1);
//hide the button and the edit text
btn.setVisibility(View.GONE);
edt.setVisibility(View.GONE);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String edittext= edt.getText().toString();
Pattern pat= Pattern.compile("[0-9]");
// Pattern pat= Pattern.compile("[a-zA-Z0-9]");
Matcher matcher = pat.matcher(edittext);
//*************Timer Start *************************8
//11000 = 10 seconds(11000*6*60 == 1hour)
int count = 11000;
timer = new CountDownTimer(count, 1000)
{public void onTick(long millisUntilFinished)
{
long scnds=0;
scnds=(millisUntilFinished/1000);
}
public void onFinish()
{//Alaram cooooode **********************************************************
Calendar cal = Calendar.getInstance(); //for using this you need to import java.util.Calendar;
AlarmManager am = (AlarmManager)parent.getContext().getSystemService(Context.ALARM_SERVICE);
ArrayList<PendingIntent> intentArray = new ArrayList<PendingIntent>();
//the title and the description of the notification
Intent alarmintent = new Intent(parent.getContext(), Alarm_Receiver.class);
alarmintent.putExtra("title",titlePills + "value");
alarmintent.putExtra("note","value");
//HELLO_ID is a static variable that must be initialized at the BEGINNING OF CLASS with 1;
//example:protected static int HELLO_ID =1;
PendingIntent sender = PendingIntent.getBroadcast(parent.getContext(), CountMultipleAlarm++,
alarmintent,PendingIntent.FLAG_UPDATE_CURRENT);
//VERY IMPORTANT TO SET FLAG_UPDATE_CURRENT... this will send correct extra's informations to
//AlarmReceiver Class
// Get the AlarmManager service
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
//Alarm coooooode end **************************************
intentArray.add(sender);
timer.start();
}
}.start();
//*************Timer Ends *************************8
}
});
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}import
and this is the alarm_Receiver class
public class Alarm_Receiver extends BroadcastReceiver {
String notification1 = "You Pills Time ";
private static int NOTIFICATION_ID = 1;
#Override
public void onReceive(Context context, Intent intent) {
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationManager manger = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, notification1,
System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(context,
NOTIFICATION_ID,
new Intent(context, Alarm_Receiver.class), 0);
Bundle extras=intent.getExtras();
String title=extras.getString("title");
//here we get the title and description of our Notification
//
String note=extras.getString("note");
notification.setLatestEventInfo(context, note, title, contentIntent);
notification.flags = Notification.FLAG_INSISTENT;
notification.defaults |= Notification.DEFAULT_SOUND;
//here we set the default sound for our
//notification
// The PendingIntent to launch our activity if the user selects this notification
manger.notify(NOTIFICATION_ID++, notification);
}
};
You are overwriting the old one because the request code that you use in getBroadcast() is always zero.
PendingIntent sender = PendingIntent.getBroadcast(parent.getContext(), i++, alarmintent,
PendingIntent.FLAG_UPDATE_CURRENT | Intent.FILL_IN_DATA);
The value of i is always zero, because you always set it to zero before calling getBroadcast().
Hi, I have a problem with my code.I typed my code to be work on a multiple alarms every alarm take 10 seconds to be triggered REPEATEDLY.My problem is that the alarm works with just one value but although I've put a different requestCode,but it doesn't work or I don't know how I can call every one separately .
I've tried to do this:
alarm1 with a value and a request code 0 (for example) for 10 seconds
alarm2 with a different value and a request code 1 (for example) for
10 seconds
The code does:
Display Alarm2 that I selected last.
static int HELLO_ID = 1;
boolean flag = false;
int CountMultipleAlarm = 0;
EditText edt,edt2;
Button btn;
CountDownTimer timer;
//the strings of the notifications
String titlePills = "Time to take Panadol",DescriptionPills = "Panadol";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.planets_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
btn = (Button)findViewById(R.id.button1);
edt = (EditText)findViewById(R.id.editText1);
//hide the button and the edit text
btn.setVisibility(View.GONE);
edt.setVisibility(View.GONE);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String edittext= edt.getText().toString();
Pattern pat= Pattern.compile("[0-9]");
// Pattern pat= Pattern.compile("[a-zA-Z0-9]");
Matcher matcher = pat.matcher(edittext);
//*************Timer Start ******************
//11000 = 10 seconds(11000*6*60 == 1hour)
int count = 11000;
timer = new CountDownTimer(count, 1000)
{public void onTick(long millisUntilFinished)
{
long scnds=0;
scnds=(millisUntilFinished/1000);
}
public void onFinish()
//****** Alarm Code ********
Calendar cal = Calendar.getInstance();
// for using this you need to import java.util.Calendar;
AlarmManager am = (AlarmManager)parent.getContext().getSystemService(Context.ALARM_SERVICE);
ArrayList<PendingIntent> intentArray = new ArrayList<PendingIntent>();
//the title and the description of the notification
Intent alarmintent = new Intent(parent.getContext(), Alarm_Receiver.class);
alarmintent.putExtra("title",titlePills + "value");
alarmintent.putExtra("note","value");
//HELLO_ID is a static variable that must be initialized at the BEGINNING OF CLASS with 1;
//example:protected static int HELLO_ID =1;
PendingIntent sender = PendingIntent.getBroadcast(parent.getContext(), CountMultipleAlarm++,
alarmintent,PendingIntent.FLAG_UPDATE_CURRENT);
//VERY IMPORTANT TO SET FLAG_UPDATE_CURRENT... this will send correct extra's informations to
//AlarmReceiver Class
// Get the AlarmManager service
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
//Alarm coooooode end **************************************
intentArray.add(sender);
timer.start();
}
}
//************* Timer Ends *************
}
});
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}import
//Edit from Paramone: What comes after " }import " ???
alarm_Receiver class
public class Alarm_Receiver extends BroadcastReceiver {
String notification1 = "You Pills Time ";
private static int NOTIFICATION_ID = 1;
#Override
public void onReceive(Context context, Intent intent) {
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationManager manger = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, notification1,
System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(context,
NOTIFICATION_ID,
new Intent(context, Alarm_Receiver.class), 0);
Bundle extras=intent.getExtras();
String title=extras.getString("title");
//here we get the title and description of our Notification
String note=extras.getString("note");
notification.setLatestEventInfo(context, note, title, contentIntent);
notification.flags = Notification.FLAG_INSISTENT;
notification.defaults |= Notification.DEFAULT_SOUND;
//here we set the default sound for our notification
// The PendingIntent to launch our activity if the user selects this notification
manger.notify(NOTIFICATION_ID++, notification);
}
};
I have created an activity in which I have created a progress bar as follows, and I have written the Notification but it's not working. Notification occurs at top corner of the screen sometimes. I want that Notification as a message box in the middle of the screen. How to achieve it? My activity code as follows:
public class oddg extends Activity implements OnClickListener
{
ProgressDialog dialog;
int increment;
int maximum ;
private NotificationManager mManager;
private static final int APP_ID = 0;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Button startbtn = (Button) findViewById(R.id.startbtn);
startbtn.setOnClickListener(this);
mManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
}
#Override
public void onClick(View arg0)
{
// get the increment value from the text box
EditText et = (EditText) findViewById(R.id.increment);
// convert the text value to a integer
increment = Integer.parseInt(et.getText().toString());
dialog = new ProgressDialog(this);
dialog.setCancelable(true);
dialog.setMessage("Loading...");
// set the progress to be horizontal
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// reset the bar to the default value of 0
dialog.setProgress(0);
// get the maximum value
EditText max = (EditText) findViewById(R.id.maximum);
// convert the text value to a integer
maximum = Integer.parseInt(max.getText().toString());
// set the maximum value
dialog.setMax(maximum);
// display the progressbar
dialog.show();
// create a thread for updating the progress bar
Thread background = new Thread (new Runnable() {
public void run()
{
try
{
// enter the code to be run while displaying the progressbar.
// This example is just going to increment the progress bar:
// So keep running until the progress value reaches maximum value
while(dialog.getProgress()<= dialog.getMax())
{
// wait 500ms between each update
Thread.sleep(500);
// active the update handler
progressHandler.sendMessage(progressHandler.obtainMessage());
}
}
catch (java.lang.InterruptedException e)
{
// if something fails do something smart
}
}
});
// start the background thread
background.start();
}
// handler for the background updating
Handler progressHandler = new Handler()
{
public void handleMessage(Message msg)
{
if(dialog.getProgress()== dialog.getMax())
{
Notification notification = new Notification(R.drawable.icon,"Click here", System.currentTimeMillis());
notification.setLatestEventInfo(oddg.this,"App Name","Description of the notification",PendingIntent.getActivity(getApplicationContext(), CONTEXT_IGNORE_SECURITY, getIntent(), CONTEXT_IGNORE_SECURITY));
}
dialog.incrementProgressBy(increment);
}
};
It would be something like this
notificationMgr = context.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0,
new Intent(ctx, myActClassName.class), 0);
Notification notification = new Notification(R.drawable.icon, someText, System.currentTimeMillis());
notification.setLatestEventInfo(ctx, title, contentText, contentIntent);
int HELLO_ID = 10;
notificationManager.notify(HELLO_ID, notification);
For Status bar Notification check this
http://developer.android.com/guide/topics/ui/notifiers/notifications.html
http://javainnovations.blogspot.com/2009/05/how-to-send-message-to-status-bar-in.html