2
public class FinishService extends Service{

 private NotificationManager mNM;
 public static String ChangeDate;
 public static Context mContext;
 public static String today;



 private int NOTIFICATION = R.string.local_service_started;
 private int START_STICKY;


 public class LocalBinder extends Binder {
     FinishService getService() {
            return FinishService.this;
        }
    }




 @Override
public void onCreate() {
     mContext=FinishService.this;
      mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
         showNotification();
}



  @SuppressLint("Override")
        public int onStartCommand(Intent intent, int flags, int startId) {
            Log.i("LocalService", "Received start id " + startId + ": " + intent);
            Toast.makeText(this, "Service start", Toast.LENGTH_SHORT).show();

            // We want this service to continue running until it is explicitly
            // stopped, so return sticky.
            return START_STICKY;
        }



@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return mBinder;
}

//@Override
public void onDestroy() {

            if(AstrobixStaticMethod.isInternetAvailable(FinishService.this)){
                 Date date = Calendar.getInstance().getTime(); 
                 DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
                 ChangeDate=formatter.format(date);
                SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
                Calendar cal=Calendar.getInstance();
            try{
                cal.setTime(sdf.parse(ChangeDate));
            }catch(Exception e){

            }
            cal.add(Calendar.DATE, 1);
            ChangeDate=sdf.format(cal.getTime());
            Toast.makeText(this, ""+ChangeDate, Toast.LENGTH_SHORT).show();
            Log.e("Next Date", ChangeDate);
            RahuActivity.nextAlaram();  

            }
            else{
                Intent mIntent=new Intent(getApplicationContext(),Information.class);
                mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                mContext.startActivity(mIntent);


            }


}



private final IBinder mBinder = new LocalBinder();

 @SuppressWarnings("deprecation")
    private void showNotification() {
        // This is the 'title' of the notification
        CharSequence title = "Rahukaal has finished.!!";
        // This is the icon to use on the notification
        int icon = R.drawable.ic_launcher;
        // This is the scrolling text of the notification
        //CharSequence text =RahuParserClasses.mList.get(0);
        CharSequence text ="Rahukaal Time Finished Now";
        // What time to show on the notification
        long time = System.currentTimeMillis();
        Notification notification = new Notification(icon, text, time);
        // The PendingIntent to launch our activity if the user selects this notification
        Intent notificationIntent = new Intent();
    //  PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, RahuTimeActivity.class), 0);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
        // Set the info for the views that show in the notification panel.
        notification.setLatestEventInfo(this, title, text, contentIntent);
        // Clear the notification when it is pressed
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        //Vibrates fon on notification
        notification.vibrate=new long[] { 100, 250, 100, 500 };
        notification.defaults |= Notification.DEFAULT_SOUND;
        //Uri defaultRingtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        // Send the notification to the system.

        mNM.notify(NOTIFICATION, notification);


        stopSelf();

    }

谁能帮帮我。我做了一个应用程序,我从匹配时间设置警报。当时间匹配时,服务类正在运行,但如果手机上的互联网不可用,我已经对销毁方法进行了编码。它将转到 BroadcastReceiver 类,但它消失了,并在应用程序未打开时显示错误。

在此处查找错误:

 java.lang.RuntimeException: Unable to stop service   com.astrobix.service.FinishService@40523370: android.content.ActivityNotFoundException:    Unable to find explicit activity class { com.astrobix.astrobixrahukaal/com.astrobix.service.Information}; have you declared this activity in your AndroidManifest.xml?
4

3 回答 3

2

问题是您不能在广播接收器上使用startActivity方法尝试使用此方法。

`Intent mIntent=new Intent(FinishService.this,Information.class);

发送广播(mIntent);`

于 2013-08-01T11:34:51.987 回答
1

错误解释了您的问题

您是否在 AndroidManifest.xml 中声明了此活动?

将您的 Activity 添加到 Application 标签内的 AndroidManifest 中:

<activity android:name=".newActivity">
于 2013-08-01T10:22:37.353 回答
0

尝试这个:

Intent mIntent=new Intent(mContext,Information.class);
            mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(mIntent);

找不到明确的活动类 {com.astrobix.astrobixrahukaal/com.astrobix.service.Information};您是否在 AndroidManifest.xml 中声明了此活动?

have u added in the AndroidManifest?
于 2013-08-01T10:23:29.867 回答