he, i am new to android platform.
Now i am developing a small application based on notifications.
In my application i am maintaining a timer based on that time every time a notification is displayed.
But the problem is first time notification is displayed and the second notification is appended above the first notification , third notification is append above the second notification………………
I want to display the notifications one by one.
if any one has idea how to display the notification one by one .please reply me.
here is my code
myTimer = new Timer();
myTimer.schedule(new TimerTask()
{
@Override
public void run()
{
TimerMethod();
}
}, 10000,10000);
}
private void TimerMethod()
{
this.runOnUiThread(Timer_Tick);
}
private Runnable Timer_Tick = new Runnable()
{
public void run()
{
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(R.drawable.icon,"New Alert, Click Me!",System.currentTimeMillis());
Context context = getApplicationContext();
CharSequence contentTitle = "Notification Details...";
CharSequence contentText = "you have a new notification find clicking me";
Intent notifyIntent = new Intent(Notifi.this,Notifi.class);
PendingIntent intent =
PendingIntent.getActivity(Notifi.this, 0,
notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
}
};
Thanks in advance
Store a fixed amount of time say 5000ms in a variable.
Now, start the 1st notification and get the current system time. To this add that 5000ms and continue processing. At the end of 5000ms close the notification. If the 2nd notification must be displayed within 5secs of the 1st one, then use a if condition statement and check whether 5000ms have elapsed since the start time of 1st notification. If it has elapsed then display the 2nd one, else wait till the 1st one completes.
You can also simply check if any notification is open using a simple flag that will be set to 1 when a notification starts and to 0 when it closes. If it is 0, a new notification can be displayed.
[You may also be able to use 2 threads to do this. On 1st thread run all processes. The 2nd one just interrupts the 1st one at set periods after being started. But haven’t tried out this]
Hope I was able to help you.