Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a service in Android that can't be killed by Advanced Task Killer
    primarykey
    data
    text
    <p>I create a security application just like Mcafee wave secure.<br> My application is listening for SMS command and doing some action when the command is match, so I create a form with another service for listening the SMS. </p> <p>Here's the main form:</p> <pre><code>public static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED"; ArrayList&lt;String&gt; messageList; ArrayAdapter&lt; String&gt; adapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //untuk mendisable notification area requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main); MainButtonAbout=(Button) findViewById(R.id.MainbuttonAbout); MainButtonHelp=(Button) findViewById(R.id.MainbuttonHelp); MainButtonWizard=(Button) findViewById(R.id.MainbuttonWizard); MainButtonOption=(Button) findViewById(R.id.MainbuttonOption); MainCheckBoxActive=(CheckBox)findViewById(R.id.MaincheckBoxActive); MainButtonAbout.setOnClickListener(this); MainButtonHelp.setOnClickListener(this); MainButtonWizard.setOnClickListener(this); MainButtonOption.setOnClickListener(this); startService(new Intent(MainForm.this, ListenSMSservice.class)); MainCheckBoxActive.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if (buttonView.isChecked()) { Toast.makeText(MainForm.this, "Your Device is Protected Now!!", 1).show(); startService(new Intent(MainForm.this, ListenSMSservice.class)); } else { Toast.makeText(MainForm.this, "Your Device is not Protected Now!!", 1).show(); stopService(new Intent(MainForm.this, ListenSMSservice.class)); } } }); } public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.MainbuttonAbout: Intent GoToAbout= new Intent(this,AboutForm.class); startActivity(GoToAbout); break; case R.id.MainbuttonHelp: Intent GoToHelp= new Intent(this,HelpForm.class); startActivity(GoToHelp); break; case R.id.MainbuttonWizard: Intent GoToWizard1= new Intent(this,WizardForm1.class); startActivity(GoToWizard1); break; case R.id.MainbuttonOption: Intent GoToOption= new Intent(this,OptionForm.class); startActivity(GoToOption); break; default: break; } } </code></pre> <p>and this is the Service form:</p> <pre><code>@Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); } /*@Override public void onStart(Intent intent, int startid) { Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show(); ListenSMS(); }*/ @Override public int onStartCommand(Intent intent, int flags, int startId) { ListenSMS(); // We want this service to continue running until it is explicitly // stopped, so return sticky. return START_STICKY; } private void ListenSMS() { // TODO Auto-generated method stub messageList = new ArrayList&lt;String&gt;(); adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, messageList); //Toast.makeText(this, "Masuk bagian sini sudah", 1).show(); IntentFilter filter = new IntentFilter(SMS_RECEIVED); registerReceiver(receiver_SMS, filter); } BroadcastReceiver receiver_SMS = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(SMS_RECEIVED)) { Bundle bundle = intent.getExtras(); if (bundle != null) { Object[] pdus = (Object[]) bundle.get("pdus"); SmsMessage[] messages = new SmsMessage[pdus.length]; for (int i = 0; i &lt; pdus.length; i++) messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); for (SmsMessage message : messages) { Toast.makeText(ListenSMSservice.this, "isi pesan &gt;&gt; "+message.getDisplayMessageBody(), Toast.LENGTH_LONG).show(); receivedMessage(message.getDisplayOriginatingAddress()); if (message.getDisplayMessageBody().toString().equalsIgnoreCase("aaaa")) { Toast.makeText(ListenSMSservice.this, "messegenya aaaa", 1).show(); } } } } } }; private void receivedMessage(String message) { messageList.add(message); adapter.notifyDataSetChanged(); } @Override public void onDestroy() { Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show(); } </code></pre> <p>Unfortunately, my service can be stopped by Advanced task killer, so I can't listen for the SMS command.</p> <p>I'm using <code>start_sticky</code> option, but it does not work for me.<br> Does anyone have an idea how to handle that problem, so I can listen to the SMS (auto started service) even when task killer was used to kill my application?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload