2013-06-03 3 views
18

나는 이것을 알아 냈다고 생각했지만,이 질문에 대해 디버깅을 한 후 : How to make notification uncancellable/unremovable 방금 ​​내 활동이 onCreated() 및 onDestroyed()를 임의의 순서로 사용하고 있음을 알게되었습니다. 활동에 대한알림을 다시 시작하고 활동을 다시 작성하지 않으려면 어떻게합니까?

내 매니페스트 :

<activity 
     android:name="***.***.***.*****" 
     android:configChanges="orientation|keyboardHidden" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" 
     android:launchMode="singleTop" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

나는 또한 시도했다 launchmodes singleTask, singleInstance. 신고를위한

내 의도 코드 : 이것은 일부를 제공

당신이 볼 수 있듯이, 나는 그것이 관련이있을 수있는 것 같았다 모든 플래그,하지만 행운을 시도했습니다

Intent intent = new Intent(context, MyClass.class); 
    intent.setAction(Intent.ACTION_MAIN); 
    intent.addCategory(Intent.CATEGORY_LAUNCHER); 
    //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    //intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); 
    //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    //intent.setFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); 
    //intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 

... 알림을 클릭 할 때마다 AlarmManager를 다시 시작하고 alarmmanager 시작 - 작업을 시작하는 것과 같은 원치 않는 결과물. 나는 이것을 피하고 싶다.

제안 사항?

편집 :이 같은 질문의 톤이있다 알고 있지만 제공하는 솔루션 중 어느 것도 여기에 트릭을 할 것 없습니다 ... :/

Edit2가이 :

: 요청에 의해, 여기 내 클래스의
package ***.***.***; 

import android.net.ConnectivityManager; 
import android.net.NetworkInfo; 
import android.os.Build; 
import android.os.Bundle; 
import android.annotation.TargetApi; 
import android.app.Activity; 
import android.app.AlarmManager; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.content.Context; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.graphics.PorterDuff; 
import android.support.v4.app.FragmentActivity; 
import android.support.v4.app.NotificationCompat; 
import android.support.v4.app.TaskStackBuilder; 
import android.util.Log; 
import android.view.Menu; 
import android.view.View; 
import android.widget.Button; 
import android.widget.TextView; 
import android.widget.Toast; 


public class MyClass extends FragmentActivity { 


private static String userName; 
String password; 
private static Boolean LoggedIn = false; 
private static Boolean RunningState = false; 
private static Boolean OnlineState = false; 
private static String LastReportTime; 

private static Boolean isVisible = true; 
private static Boolean firstStart = true; 

private static TextView onlineTextView; 
private static TextView reportTimeTextView; 
private static TextView runningStatusTextView; 
private static TextView userLoggedInTextView; 

private static Context context; 

public static final String PREFS_NAME = "Settings"; 

public static final String NOTIFICATION_RUNNING_OK = "Reporting Active"; 
public static final String NOTIFICATION_USER_STOPPED = "Reporting Stopped"; 
public static final String NOTIFICATION_NO_NETWORK = "No Network Connected"; 
public static final String NOTIFICATION_NO_CONNECTION = "No Connection To Server"; 

public static final int NOTIFICATION_ID = 10; 

public static final int LOGIN_REQUEST_CODE = 1; 
public static final int WAKEUP_LOGIN_REQUEST_CODE = 2; 

@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 

    Log.d("MyClass", "Main onCreate() Called"); 

    loadVariables(); 

    com.remobjects.sdk.TypeManager.setPackage("com.remobjects.sdk"); 
    //if (firstStart) 
    //{ 
     Log.d("MyClass", "Main onCreate() firstStart Called"); 
     if (RunningState && checkConnection()) 
     { 
      // After runLogin(), onResume() gets called here again immediately 
      setLoginCode(LOGIN_REQUEST_CODE); 
      runLogin(); 
     } 
     else 
      init(); 
    //} 
} 

@Override 
protected void onStart() { 
    // TODO Auto-generated method stub 
    super.onStart(); 
} 

@Override 
public void onResume() 
{ 
    super.onResume(); 

    Log.d("MyClass", "Main onResume() Called"); 
    //firstStart gets set to false during login 
    if (!firstStart) 
    { 
     Log.d("MyClass", "Main onResume() !firstStart Called"); 
     loadVariables(); 
     setVisible(true); 
     updateUI(); 
    } 
} 

@Override 
protected void onPause() 
{ 
    super.onPause(); 
    saveVariables(); 
    setVisible(false); 
} 

@Override 
protected void onStop() 
{ 
    super.onStop(); 

    saveVariables(); 
    setVisible(false); 
} 

@Override 
public void onDestroy() 
{ 
    super.onDestroy(); 
    //cancelNotification(); 
    Log.e("MyClass", "onDestroy() called"); 
    saveVariables(); 
    setVisible(false); 
    //setFirstStart(true); 
} 


private void loadVariables() 
{ 
    SharedPreferences sharedPrefs = getSharedPreferences(PREFS_NAME, 0); 

    userName = sharedPrefs.getString("userName", ""); 
    RunningState = sharedPrefs.getBoolean("RunningState", true); 
    LoggedIn = sharedPrefs.getBoolean("LoggedIn", false); 
    OnlineState = sharedPrefs.getBoolean("OnlineState", false); 
    LastReportTime = sharedPrefs.getString("LastReportTime", ""); 

    context = this.getApplicationContext(); 
} 

private static void saveVariables() 
{ 
    SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0); 
    SharedPreferences.Editor editor = settings.edit(); 

    editor.putString("userName", userName); 
    editor.putBoolean("RunningState", RunningState); 
    editor.putBoolean("LoggedIn", LoggedIn); 
    editor.putBoolean("OnlineState", OnlineState); 
    editor.putString("LastReportTime", LastReportTime); 

    editor.commit(); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.activity_my_class, menu); 
    return true; 
} 

private Boolean checkConnection() 
{ 
    Log.d("MyClass", "checkConnection()"); 
    ConnectivityManager cnnxManager = (ConnectivityManager) 
      getSystemService(Context.CONNECTIVITY_SERVICE); 

    NetworkInfo ni = cnnxManager.getActiveNetworkInfo(); 

    if (ni != null && ni.isAvailable() && ni.isConnected()) 
    { 
     OnlineState = true; 
     return true; 
    } 
    OnlineState = false; 
    return false; 
} 

public void runLogin() 
{ 
    Intent intent = new Intent(context, LoginActivity.class); 
    startActivityForResult(intent, getLoginCode()); 
    Log.d("MyClass", "runLogin()"); 
} 

private void init() 
{ 
    Log.d("MyClass", "init()"); 
    setContentView(R.layout.activity_field_agent); 

    onlineTextView = (TextView)findViewById(R.id.onlineStatusTextView); 
    reportTimeTextView = (TextView)findViewById(R.id.lastReportTimeTextView); 
    runningStatusTextView = (TextView)findViewById(R.id.runningStatusTextView); 
    userLoggedInTextView = (TextView)findViewById(R.id.userLoggedInTextView); 

    findViewById(R.id.button_online).getBackground().setColorFilter(0xFF00FF00, PorterDuff.Mode.MULTIPLY); 
    findViewById(R.id.button_highRisk).getBackground().setColorFilter(0xFFFFA500, PorterDuff.Mode.MULTIPLY); 
    findViewById(R.id.button_alarm).getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY); 

    setVisible(true); 

    updateUI(); 

    if (RunningState) 
    { 
     setupAlarmManager(AlarmManager.INTERVAL_FIFTEEN_MINUTES); 
     // Here onResume() gets called again 
     updateNotificationText(NOTIFICATION_RUNNING_OK); 

     Button temp = (Button)findViewById(R.id.button_online); 
     temp.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check_box, 0, R.drawable.check_box, 0); 
    } 
    else 
    { 
     //cancelAlarmManager(); 

     updateNotificationText(NOTIFICATION_USER_STOPPED); 

     Button temp = (Button)findViewById(R.id.button_offline); 
     temp.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check_box, 0, R.drawable.check_box, 0); 
    } 
} 

private void updateUI() 
{ 
    Log.d("MyClass", "updateUI()"); 

    updateUserLoggedInStatus(userName); 

    updateOnlineStatus(OnlineState); 

    updateRunningStatus(RunningState); 

    updateReportTimeStatus(LastReportTime); 
} 

public void offDutyButton_click(View view) 
{ 
    cancelAlarmManager(); 
    Button temp = (Button)findViewById(R.id.button_offline); 
    temp.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check_box, 0, R.drawable.check_box, 0); 

    temp = (Button)findViewById(R.id.button_online); 
    temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); 

    temp = (Button)findViewById(R.id.button_highRisk); 
    temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); 

    temp = (Button)findViewById(R.id.button_alarm); 
    temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); 
} 

public void onDutyButton_click(View view) 
{ 
    Button temp = (Button)findViewById(R.id.button_online); 
    temp.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check_box, 0, R.drawable.check_box, 0); 

    temp = (Button)findViewById(R.id.button_offline); 
    temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); 

    temp = (Button)findViewById(R.id.button_highRisk); 
    temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); 

    temp = (Button)findViewById(R.id.button_alarm); 
    temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); 
    //cancelAlarmManager(); 
    setupAlarmManager(AlarmManager.INTERVAL_FIFTEEN_MINUTES); 
} 

public void highRiskButton_click(View view) 
{ 
    Button temp = (Button)findViewById(R.id.button_highRisk); 
    temp.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check_box, 0, R.drawable.check_box, 0); 

    temp = (Button)findViewById(R.id.button_online); 
    temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); 

    temp = (Button)findViewById(R.id.button_offline); 
    temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); 

    temp = (Button)findViewById(R.id.button_alarm); 
    temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); 
} 

public void alarmButton_click(View view) 
{ 
    Button temp = (Button)findViewById(R.id.button_alarm); 
    temp.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check_box, 0, R.drawable.check_box, 0); 

    temp = (Button)findViewById(R.id.button_online); 
    temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); 

    temp = (Button)findViewById(R.id.button_highRisk); 
    temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); 

    temp = (Button)findViewById(R.id.button_offline); 
    temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); 
} 

public static void setButtonIcon(int inId) 
{ 

} 

public static void showToast(String inString, Context context) 
{ 
    Toast.makeText(context, inString.toString(), Toast.LENGTH_SHORT).show(); 
} 

public static void updateOnlineStatus(Boolean inStatus) 
{ 
    if (isVisible) 
    { 
     if (inStatus) 
      onlineTextView.setText("Online"); 
     else 
      onlineTextView.setText("Offline"); 
    } 
} 

public static void updateReportTimeStatus(String inString) 
{ 
    if (isVisible) 
     reportTimeTextView.setText(inString); 
} 

public static void updateRunningStatus(Boolean inStatus) 
{ 
    if (isVisible) 
    { 
     if (inStatus) 
      runningStatusTextView.setText("Reporting"); 
     else 
      runningStatusTextView.setText("Not Reporting"); 
    } 
} 

public static void updateUserLoggedInStatus(String inString) 
{ 
    if (isVisible) 
     userLoggedInTextView.setText(inString); 
} 


// 
// 
// Getters and Setters 
// 
// 
public static void setLoggedIn(Boolean inBool) 
{ 
    LoggedIn = inBool; 
} 

public static Boolean getLoggedIn() 
{ 
    return LoggedIn; 
} 

public static void setRunningState(Boolean inBool) 
{ 
    RunningState = inBool; 
} 

public static Boolean getRunningState() 
{ 
    return RunningState; 
} 

public static void setVisible(Boolean inBool) 
{ 
    isVisible = inBool; 
} 

public static Boolean getVisible() 
{ 
    return isVisible; 
} 

public static void setUsername(String inString) 
{ 
    userName = inString; 
} 

public static String getUsername() 
{ 
    return userName; 
} 

public static void setLastReportTime(String inString) 
{ 
    LastReportTime = inString; 
} 

public static String getLastReportTime() 
{ 
    return LastReportTime; 
} 

public static Context getAppContext() 
{ 
    return MyClass.context; 
} 

public static void setLoginCode(int code) 
{ 
    SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0); 
    SharedPreferences.Editor editor = settings.edit(); 

    editor.putInt("LoginCode", code); 

    editor.commit(); 
} 

public static int getLoginCode() 
{ 
    SharedPreferences sharedPrefs = context.getSharedPreferences(PREFS_NAME, 0); 

    return sharedPrefs.getInt("LoginCode", 1); 
} 

public static void setFirstStart(Boolean inBool) 
{ 
    firstStart = inBool; 
} 

public static Boolean getFirstStart() 
{ 
    return firstStart; 
} 

// 
// 
// 
// 
// 
@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    switch(requestCode) { 
    case (LOGIN_REQUEST_CODE) : { 
     if (resultCode == Activity.RESULT_OK) { 
     LoggedIn = data.getBooleanExtra("LoggedIn", false); 
     userName = data.getStringExtra("Username"); 

     init(); 
     } 
     break; 
    } 
    case (WAKEUP_LOGIN_REQUEST_CODE) : { 
     if (resultCode == Activity.RESULT_OK) { 
      LoggedIn = data.getBooleanExtra("LoggedIn", false); 
      userName = data.getStringExtra("Username"); 

      cancelAlarmManager(); 
      setupAlarmManager(AlarmManager.INTERVAL_FIFTEEN_MINUTES); 
     } 
     break; 
    } 
    } 
} 

// 
// 
// AlarmManager 
// 
// 

public static void setupAlarmManager(long interval) 
{ 
    AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); 
    Intent alarmIntent = new Intent(context, LaunchReceiver.class); 
    PendingIntent pendingAlarmIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, alarmIntent, 0); 
    alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 0, interval, pendingAlarmIntent); 

    RunningState = true; 
    updateRunningStatus(RunningState); 

    updateNotificationText(NOTIFICATION_RUNNING_OK); 

    Log.d("MyClass", "AlarmManager Started"); 
} 


public static void cancelAlarmManager() 
{ 
    Intent intent = new Intent(context.getApplicationContext(), LaunchReceiver.class); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0); 
    AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); 
    alarmMgr.cancel(pendingIntent); 

    RunningState = false; 
    updateRunningStatus(RunningState); 

    updateNotificationText(NOTIFICATION_USER_STOPPED); 

    Log.d("MyClass", "AlarmManager Stopped"); 

    Intent serviceIntent = new Intent(context, MonitorService.class); 
    context.stopService(serviceIntent); 
    Log.d("MyClass", "Stopping MonitorService"); 
} 



// 
// 
// Notification 
// 
// 

@TargetApi(Build.VERSION_CODES.JELLY_BEAN) 
public static void createNotification() 
{ 
    NotificationManager notificationManager = (NotificationManager)context.getSystemService(NOTIFICATION_SERVICE); 

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context) 
          .setContentTitle("blablabla") 
          .setContentText("Getting Status") 
          .setSmallIcon(R.drawable.ic_launcher) 
          .setOngoing(true) 
          .setAutoCancel(false); 

    Intent intent = new Intent(context, MyClass.class); 
    intent.setAction(Intent.ACTION_MAIN); 
    intent.addCategory(Intent.CATEGORY_LAUNCHER); 
    //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    //intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); 
    //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    //intent.setFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); 
    //intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); 
    stackBuilder.addParentStack(MyClass.class); 
    stackBuilder.addNextIntent(intent); 

    PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); 

    builder.setContentIntent(pendingIntent); 

    /*Notification noti = builder.build(); 
    noti.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;*/ 

    notificationManager.notify(NOTIFICATION_ID, builder.build()); 
} 

public static void updateNotificationText(String inString) 
{ 
    NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); 

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context) 
              .setContentText(inString) 
              .setContentTitle("blablabla") 
              .setSmallIcon(R.drawable.ic_launcher) 
              .setOngoing(true) 
              .setAutoCancel(false); 

    Intent intent = new Intent(context, MyClass.class); 
    intent.setAction(Intent.ACTION_MAIN); 
    intent.addCategory(Intent.CATEGORY_LAUNCHER); 
    //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); 
    stackBuilder.addParentStack(MyClass.class); 
    stackBuilder.addNextIntent(intent); 

    PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); 

    builder.setContentIntent(pendingIntent); 

    /*Notification noti = builder.build(); 
    noti.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;*/ 

    notificationManager.notify(NOTIFICATION_ID, builder.build()); 
} 

public static void cancelNotification() 
{ 
    NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); 

    notificationManager.cancel(NOTIFICATION_ID); 
} 
} 

주석에서 언급했듯이 loginActivity를 시작한 후 onResume()이 즉시 다시 호출됩니다. alarmManager를 시작한 후에 동일합니다.

또한 alarmManager가 틱 할 때마다 앱을 포 그라운드로 가져 오는 것으로 보입니다. 그걸 피하는 방법은 없나요?

+0

활동이 생성되거나 임의 순서로 삭제되지 않습니다. 모든 관련 코드를 게시하십시오. (알림을 만드는 클래스의 코드와 알림이 연결되는 클래스) – Knossos

+0

@Knossos 관련 클래스를 추가했습니다. – CeeRo

+0

이 도움이되었습니다. http://stackoverflow.com/questions/3305088/how-to-make-notification - 이력서 - 오히려 -보다 - 새로운 의도를 만들기/39482464 # 39482464 – TharakaNirmana

답변

31

은 (알림 안드로이드 가이드에서 바로 촬영 본다

완전한 예를 들어 내가

Intent intent = new Intent(getApplicationContext(), myactivity.class); 
PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), (int)System.currentTimeMillis(), intent, 0); 

Notification myNotification = new Notification.Builder(getApplicationContext()) 
         .setContentTitle("Title") 
         .setContentText("Some text....") 
         .setSmallIcon(R.drawable.myicon) 
         .setContentIntent(pIntent) 
         .setAutoCancel(true).build(); 


NotificationManager notificationManager = 
         (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

notificationManager.notify(0, myNotification); 
+0

그 캐치에 감사드립니다! – Adgezaza

+0

이것은 많은 도움이되었습니다. 감사합니다. –

+0

@CeeRo : 방금 내 정신을 잘 보냈습니다, 고마워요 – Baggers

1

활동에 대한 BackPressed에서 오버라이드 한 적이 있습니까? 내 생각에 onBackPressed를 오버라이드하지 않으면 안드로이드의 기본값은 Activity를 파괴 (finish())하는 것이다. 따라서 이전 상태로 돌아가는 경우 알림은 활동이 이미 있는지 여부를 확인하고 없음을 찾은 다음 새 것을 만듭니다.

+2

이것은 활동을 열어 알림 막대를 당기고 통보를 클릭하더라도 ... – CeeRo

0

여러 번 실행되는 코드가 많습니다.

제거 : 중지시에서

saveVariables(); 
setVisible(false); 

() 및들의 OnDestroy(). 이 코드는 항상 onPause()에서 처음 실행됩니다.

loadVariables(); 또한 두 번 달릴 수도 있습니다. onCreate()에 한 번, onResume()에 한 번.

로드 논리를 다소 변경하는 것이 좋습니다.

init() 코드가 두 번 실행되었을 수 있습니다. onCreate()에 한 번, onActivityResult()에 한 번.

TL, 실제 문제에 관해서는 DR : 당신이해야 생각할 때 항상 발생하지 않는다는 점에서

하여 onActivityResult()는 때때로 약간 이상한이다. onActivityResult()에서 init() 전에 변수를로드 해보십시오.

이것을 실험하려면 onCreate(), onStart(), onResume() 및 onActivityResult()에 로그를 기록하고 각각 시작될 때 알립니다.

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
:이 그것을 해결 같은

TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); 
    stackBuilder.addParentStack(FieldAgent.class); 
    stackBuilder.addNextIntent(intent); 

    PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); 

일반 pendingintent로 교체 : 문제가 통지-코드에서이 라인에 의한 것처럼

+0

로깅 중입니다 광인처럼 벌써 : P 나는 alarmManager를 시작하고 멈추는 약간의 작은 변화를 만들었습니다. (나는 내가했던 것처럼 자주 할 필요가 없다고 생각합니다.) 또한 onStop 및 onDestroy에서 코드를 제거했으며 일부 이상한 이유로 onDestroy에있는 코드가 적을수록 호출되는 횟수가 줄어 듭니다. 이제 알림을 클릭 할 때 전혀 호출되지 않는 것 같습니다. (지금까지 적어도 20-30 번만 클릭했습니다.) ... 계속하려면 – CeeRo

+0

알림을 클릭해도 여전히 활동이 이루어집니다. onCreate()에서 다시 시작하십시오. 그 이후의 프로세스는 내가 기대했던대로 새로운 시작을 원하지만 이것은 새로운 시작이 아닐 뿐더러 이력서가 될 것입니다 ... 그건 내 실제 문제입니다;) – CeeRo

+0

사실 나는 틀 렸습니다. 알림을 클릭 했으므로 onCreate에 전화를 걸었습니다 (12:46:31, 12:46:36, 12:46:40, 12:47:55). 갑자기 12시 50 분 07 초에 모든 온 데스트로이가 나타났습니다. 그것들은 현재 버전을 파괴하지 않지만, 그 파괴 이후의 로그의 다음 항목은 onResume()이며 심지어! firstStart 버전입니다. 나는 혼란스러워. 통지가 활동을 재창조하게 만드는 원인은 무엇입니까? – CeeRo

3

경우 모르는 내 너와 같은 사건. 의도를 만들어 보았습니다. pageviewer + fragment를 사용하고 있습니다. 내 경우, 다시 응용 프로그램을 시작 후 집 주에 응용 프로그램을 이동 알림 메시지를 클릭, 활동, (클래스 조각이 코드)

Intent intent = new Intent(getActivity(),MainActivity.class); 
intent.addCategory(Intent.CATEGORY_LAUNCHER); 
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
PendingIntent pendingIntent = PendingIntent.getActivity(getActivity(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 

지금은 괜찮아요을 다시이 코드로 변경 :

Intent intent = getActivity().getIntent(); 
PendingIntent pendingIntent = PendingIntent.getActivity(getActivity(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 

희망이 도움말^_^

5

제 경우에는 대답이 CeeRo에 의해 작동했지만 이상한 방식으로 진행됩니다. 나는 전화를 다시 시작해야했다! :)

+0

나를 위해, 그것은 어색하다 ... – bercik

+0

나를 위해. 감사. – mihai1990