2013-05-28 25 views
0
public void AddCustomEvent() { 
     ListView lv = (ListView) findViewById(R.id.listView1); 


     final Set<String> tasks = sp.getStringSet("tasks", new HashSet<String>()); 

     ArrayList<String> taskarr = new ArrayList<String>(); 

     lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> parent, View view, 
            int position, long id) { 

       Log.i("Hello!", String.valueOf(position) + " " + String.valueOf(id)); 

       final int pos = position; 
       AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
         getApplicationContext()); 

       // set title 
       alertDialogBuilder.setTitle("Do you want to delete this task"); 

       // set dialog message 
       alertDialogBuilder 
         .setMessage("Click yes to delete !") 
         .setCancelable(false) 
         .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int id) { 
           // if this button is clicked, close 
           // current activity 


           Set<String> tasks = sp.getStringSet("tasks", new HashSet<String>()); 

           final ListView listview = (ListView) findViewById(R.id.listView1); 

           final ArrayList<String> list = new ArrayList<String>(); 
           for (String str : tasks) { 
            list.add(str); 
           } 
           list.remove(pos); 

           Set<String> newTasks = new HashSet<String>(); 

           for (String str : list) { 
            newTasks.add(str); 
           } 

           Editor edit = sp.edit(); 

           edit.putStringSet("tasks", newTasks); 

           edit.commit(); 

           final StableArrayAdapter adapter = new StableArrayAdapter(getApplicationContext(), 
             android.R.layout.simple_list_item_1, list); 

           listview.setAdapter(adapter); 

          } 
         }) 
         .setNegativeButton("No", new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int id) { 
           // if this button is clicked, just close 
           // the dialog box and do nothing 
           dialog.cancel(); 
          } 
         }); 

       // create alert dialog 
       AlertDialog alertDialog = alertDialogBuilder.create(); 

       // show it 
       alertDialog.show(); 


      } 

     }); 
    } 

我做了一個任務應用程序。在刪除任務之前顯示alertdialog。沒有特別的。我的代碼因爲崩潰(我想顯示alertdialog)而被破壞。以下代碼中的服務泄漏在哪裏?

做某人檢查代碼,讓我知道如何以及在哪裏泄漏服務。

http://pastebin.com/edsS9CQh

+0

你的logcat輸出在哪裏? – Snicolas

+0

@Snicolas我在這篇文章中附加了pastebin鏈接。它是否可見:) – user2126670

回答

0

無級你的堆棧跟蹤被提及。除非您實際使用包名稱編寫應用程序:com.android.emailcommon.utility。但我想你不會在這裏問問題:)

+0

我使用Android Studio和應用程序名稱,如果流量。它有一定的流動性。搜索就可以了。也許你會發現錯誤 – user2126670

+0

我的應用程序使用sharepreference和alertdialog沒有別的。我怎樣才能讓自己確信哪裏出了問題? – user2126670

+0

的代碼工作正常如果我刪除alertdialog。你能檢查這部分代碼嗎?我在alertdiaolog代碼塊裏面出了點問題 – user2126670