دوستان در همین رابطه من کد نوتیفیکیشن رو توی یه کلاس به نام Notif به صورت زیر نوشتم
این کد باید باعث بشه تا ده ثانیه دیر تر نوتیفیکیشن از کلاس Notif اجرا بشه
و حالا میخوام با کد زیر توی Main Activity اجراش کنم
ولی سر ده ثانیه Force Close میده........ مشکل رو چطور حل کنم؟؟؟؟
(دقت کنید که این کد بدون قسمت تاخییر به درستی اجرا میشه،،، فقط توی کد تاخیر که میذارمش force close میده)
این کد باید باعث بشه تا ده ثانیه دیر تر نوتیفیکیشن از کلاس Notif اجرا بشه
کد پیاچپی:
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
public class Notif {
public static void Notificationm(Context context){
NotificationManager nm=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notify=new Notification(R.drawable.ic_launcher,"شما یک پیام دارید",System.currentTimeMillis());
notify.flags |= Notification.FLAG_AUTO_CANCEL; //Do not clear the notification
notify.flags |= Notification.FLAG_NO_CLEAR; //Do not clear the notification
notify.flags |= Notification.FLAG_SHOW_LIGHTS; //Do not clear the notification
notify.defaults |= Notification.DEFAULT_LIGHTS; // LED
notify.defaults |= Notification.DEFAULT_SOUND; // Sound
CharSequence title="Title";
CharSequence detils="Detils";
Intent nazar = new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://cafebazaar.ir/"));
//Intent intent=new Intent(context,send.class );
PendingIntent pend=PendingIntent.getActivity(context, 0, nazar, 0);
notify.setLatestEventInfo(context, title, detils, pend);
nm.notify(0,notify);
}
}
و حالا میخوام با کد زیر توی Main Activity اجراش کنم
کد پیاچپی:
new CountDownTimer(10000,1000){
@Override
public void onTick(long millisUntilFinished){}
@Override
public void onFinish(){
// your code
Notif.Notificationm(MainActivity.this);
}
}.start();
ولی سر ده ثانیه Force Close میده........ مشکل رو چطور حل کنم؟؟؟؟
(دقت کنید که این کد بدون قسمت تاخییر به درستی اجرا میشه،،، فقط توی کد تاخیر که میذارمش force close میده)