2015-05-01 84 views
0

所以我的應用程序會在addParentStack()得到執行後立即停止響應,並且會出現一個彈出窗口,表示應用程序沒有響應,選擇等待或關閉它,很快我關閉它,它會告訴我之前的活動是在碰撞發生之前還是沒有發生。 更大的問題是,有一個在設備logcat的任何錯誤信息,所以我無法找到問題的根源 這裏是我的代碼是主要的活動的一部分Android - TaskStackBuilder .addParentStack讓我的應用程序沒有響應

public void addNotif(DetailEvent detailEvent) { 
    Intent resultIntent = new Intent(this, Agenda.class); 
//  resultIntent.putExtra("eventName", detailEvent.getEventName()); 
    resultIntent.putExtra("eventName",detailEvent.getEventName()); 
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
    builder.setContentTitle(detailEvent.getEventName()); 
    builder.setContentText(detailEvent.getEventOpenHour()); 
    builder.setSmallIcon(R.drawable.ic_launcher); 
    builder.setAutoCancel(true); 
    builder.setNumber(++numMessages); 

    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this); 
    taskStackBuilder.addParentStack(add_reminder.class); 
    //add resultIntent to top of the stack 
    taskStackBuilder.addNextIntent(resultIntent); 

    PendingIntent pendingIntent = taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); 
    builder.setContentIntent(pendingIntent); 

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

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

我嘗試添加另一個類的詮釋了addParentStack參數,只有類可以正常運行,single_event類,這是我不知道爲什麼這種情況發生的一個...

這裏是我的清單

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.hansel.tapbandung_v00" > 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.tapbandung.page.Home" 
      android:label="@string/app_name" > 
     </activity> 

     <activity 
      android:name="com.tapbandung.page.Profile" 
      android:label="@string/title_activity_profile" 
      android:parentActivityName=".Host" > 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="com.example.hansel.tapbandung_v00.Host" /> 
     </activity> 
     <activity 
      android:name="com.tapbandung.page.Community" 
      android:label="@string/title_activity_community" > 
     </activity> 
     <activity 
      android:name="com.tapbandung.page.Event" 
      android:label="@string/title_activity_event" > 
      <intent-filter> 
       <action android:name="android.intent.action.SEARCH" /> 
      </intent-filter> 

      <meta-data 
       android:name="android.app.searchable" 
       android:resource="@xml/searchable" /> 
     </activity> 
     <activity 
      android:name="com.tapbandung.page.Bussiness" 
      android:label="@string/title_activity_bussiness" > 
     </activity> 
     <activity 
      android:name="com.tapbandung.page.single_event" 
      android:label="@string/title_activity_single_event" 
      android:parentActivityName="com.tapbandung.page.Event" > 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="com.tapbandung.page.Event" /> 
     </activity> 
     <activity 
      android:name="com.tapbandung.page.Agenda" 
      android:label="@string/title_activity_agenda" 
      android:parentActivityName="com.tapbandung.page.Profile" > 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="com.tapbandung.page.Profile" /> 
     </activity> 
     <activity 
      android:name=".Host" 
      android:label="@string/app_name" 
      android:parentActivityName=".Host" > 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="com.example.hansel.tapbandung_v00.Host" /> 
     </activity> 
     <activity 
      android:name="com.tapbandung.page.edit_profile" 
      android:label="@string/title_activity_edit_profile" 
      android:parentActivityName="com.tapbandung.page.Profile" > 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="com.tapbandung.page.Profile" /> 
     </activity> 
     <activity 
      android:name="com.tapbandung.page.tapped_events" 
      android:label="@string/title_activity_tapped_events" 
      android:parentActivityName="com.tapbandung.page.Profile" > 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="com.tapbandung.page.Profile" /> 
     </activity> 
     <activity 
      android:name="com.tapbandung.page.single_tapped_event" 
      android:label="@string/title_activity_single_tapped_event" 
      android:parentActivityName="com.tapbandung.page.tapped_events" > 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="com.tapbandung.page.tapped_events" /> 
     </activity> 
     <activity 
      android:name="com.tapbandung.page.login" 
      android:label="@string/app_label" 
      android:theme="@style/Theme.AppCompat.NoActionBar" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="com.tapbandung.page.signup" 
      android:label="@string/title_activity_signup" 
      android:theme="@style/Theme.AppCompat.NoActionBar" > 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="com.tapbandung.page.login" /> 
     </activity> 
     <activity 
      android:name="com.tapbandung.page.help" 
      android:label="@string/title_activity_help" 
      android:parentActivityName=".Host" > 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="com.example.hansel.tapbandung_v00.Host" /> 
     </activity> 
     <activity 
      android:name="com.tapbandung.page.about" 
      android:label="@string/title_activity_about" 
      android:parentActivityName=".Host" > 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="com.example.hansel.tapbandung_v00.Host" /> 
     </activity> 
     <activity 
      android:name="com.tapbandung.page.add_reminder" 
      android:label="@string/title_activity_add_reminder" 
      android:parentActivityName="com.tapbandung.page.Agenda" > 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="com.tapbandung.page.Agenda" /> 
     </activity> 

    </application> 

</manifest> 

這是唯一我的日誌可以得到f rom設備logcat

05-01 22:33:37.836 30470-30479/com.example.hansel.tapbandung_v00 I/art﹕ Thread[5,tid=30479,WaitingInMainSignalCatcherLoop,Thread*=0xb8e68c68,peer=0x12c000a0,"Signal Catcher"]: reacting to signal 3 
05-01 22:33:37.836 30470-30479/com.example.hansel.tapbandung_v00 I/art﹕ [ 05-01 22:33:38.036 517: 537 I/Process ] 
Sending signal. PID: 517 SIG: 3 

回答

0

看起來您可能在使用TaskStackBuilder時出錯。嘗試:

TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this); 
taskStackBuilder.addParentStack(Agenda.class); // Difference is in this line 
//add resultIntent to top of the stack 
taskStackBuilder.addNextIntent(resultIntent); 

的addParentStack()調用讀取了Android的價值:parentActivityName從清單,並添加所有適當的活動,以返回堆疊。通常情況下,您希望這是您當前啓動的活動。