Android Open Source - LheidoSMS Remove Conversation Service






From Project

Back to project page LheidoSMS.

License

The source code is released under:

GNU General Public License

If you think the Android project LheidoSMS listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lheidosms.service;
// www  .j a v  a  2s  . c  o m
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;

import com.lheidosms.app.Global;
import com.lheidosms.utils.LheidoContact;
import com.lheidosms.utils.LheidoUtils;
import com.lheidosms.utils.Message;

public class RemoveConversationService extends Service {
    private static final String SERVICE_TAG = "REMOVE CONVERSATION LOG";
    private Context context;

    @Override
    public void onCreate() {
        Log.v(SERVICE_TAG, "=====> Service start! <=====");
        context = getApplicationContext();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId){
        Log.v(SERVICE_TAG, "=====> onStartCommand <=====");
        try {
            String id = intent.getStringExtra("conversationId");
            if(id != null && !id.isEmpty()) {
                RemoveConversationTask delete = new RemoveConversationTask(id);
                delete.execTask();
            }
        }catch (Exception e){e.printStackTrace();}
        return START_STICKY;
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onDestroy(){
        Log.v(SERVICE_TAG, "=====> Service done! <=====");
        super.onDestroy();
    }

    private final class RemoveConversationTask extends AsyncTask<Void, Message, Boolean> {

        private final String id;

        public RemoveConversationTask(String id){
            this.id = id;
        }

        @Override
        protected Boolean doInBackground(Void... voids) {
            try {
                int c_index = -1;
                for (LheidoContact c : Global.conversationsList) {
                    if (c.getConversationId().equals(id)) {
                        LheidoUtils.delete_sms(context, c, 0);
                        c_index = Global.conversationsList.indexOf(c);
                        LheidoUtils.Send.notifyDataChanged(context);
                    }
                }
                if(c_index != -1){
                    Global.conversationsList.remove(c_index);
                }
            }catch (Exception e){e.printStackTrace();}
            return null;
        }

        @Override
        protected void onPostExecute (Boolean result) {
            stopSelf();
        }

        public void execTask(){
            if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ) {
                executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            } else {
                execute();
            }
        }
    }
}




Java Source Code List

com.lheidosms.adapter.ContactsListAdapter.java
com.lheidosms.adapter.ConversationAdapter.java
com.lheidosms.adapter.ListeConversationsAdapter.java
com.lheidosms.adapter.MMSAdapter.java
com.lheidosms.adapter.SmsAdapter.java
com.lheidosms.adapter.SmsBaseAdapter.java
com.lheidosms.adapter.ViewPagerAdapter.java
com.lheidosms.app.AutoComplete.java
com.lheidosms.app.Global.java
com.lheidosms.app.MainLheidoSMS.java
com.lheidosms.fragment.MMSFragment.java
com.lheidosms.fragment.NavigationDrawerFragment.java
com.lheidosms.fragment.SMSFragment.java
com.lheidosms.fragment.SmsBaseFragment.java
com.lheidosms.preference.LheidoSMSPreferenceOldApi.java
com.lheidosms.preference.LheidoSMSPreference.java
com.lheidosms.preference.PrefConversationFragment.java
com.lheidosms.preference.PrefGeneralFragment.java
com.lheidosms.preference.PrefListConversationsFragment.java
com.lheidosms.preference.PrefReceiveFragment.java
com.lheidosms.receiver.BootReceiver.java
com.lheidosms.receiver.LheidoBaseReceiver.java
com.lheidosms.receiver.MainServiceReceiver.java
com.lheidosms.receiver.MmsFragmentReceiver.java
com.lheidosms.receiver.SmsFragmentReceiver.java
com.lheidosms.receiver.SmsReceiver.java
com.lheidosms.service.DeleteOldSMSService.java
com.lheidosms.service.LheidoSMSService.java
com.lheidosms.service.MainService.java
com.lheidosms.service.RemoveConversationService.java
com.lheidosms.utils.BuildFragment.java
com.lheidosms.utils.LheidoContact.java
com.lheidosms.utils.LheidoUtils.java
com.lheidosms.utils.Message.java