Wednesday, 26 September 2018

How to close this activity? (Android)

i was created my lockscreen application that trigerred by a SMS.. i have ListenSMS class that always listen for incoming SMS.. here's the code :

for (SmsMessage message : messages)
                      {
                            String tempMessage[] = message.getDisplayMessageBody().toString().split(" ");

                            //checking command dan password                             
                            if (tempMessage[0].toString().equalsIgnoreCase("andro-lock") && tempMessage[1].toString().equals(tempPassword.toString()))  
                            {
                                //Toast.makeText(ListenSMSservice.this, "Menjalankan command andro-lock", Toast.LENGTH_LONG).show();
                                openDatabase();
                                updateStatusL();
                                Intent myIntent = new Intent(ListenSMSservice.this,LockScreenForm.class);
                                myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                getApplication().startActivity(myIntent);
                            }
                            else if (tempMessage[0].toString().equalsIgnoreCase("andro-unlock") && tempMessage[1].toString().equals(tempPassword.toString()))   
                            {
                                //Toast.makeText(ListenSMSservice.this, "Menjalankan command andro-unlock", Toast.LENGTH_LONG).show();
                                openDatabase();
                                updateStatusNL();                                                                   
                                Intent myIntent = new Intent(ListenSMSservice.this,LockScreenForm.class);
                                myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                Bundle myKillerBundle = new Bundle();
                                myKillerBundle.putString("kill","1");
                                myIntent.putExtras(myKillerBundle);
                                getApplication().startActivity(myIntent);

                            }

                      }

if ListenSMS service has receive an "andro-lock" command, it will go to the lockscreen.java and will go to the lockscreen.java with inten extra (putExtra) "kill" when it receive command "andro-unclock".. here's my lockscreen.java:

public class LockScreenForm extends Activity implements OnClickListener{
    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.lockscreen);             

        Bundle extra = getIntent().getExtras();
        if (extra == null) {
            return;
        }
        //Toast.makeText(this, extra.getString("kill"), 1).show();
        else if(this.getIntent().getExtras().getString("kill").equalsIgnoreCase("1")){
            try {
                Toast.makeText(this, "extra accepted", 1).show();
                finish();
            } catch (Exception e) {
                // TODO: handle exception
                Toast.makeText(this, e.getMessage(), 1).show();
            }

        }

    }

i want close my locksreen.java when my ListenSMS service has received "andro-unlock" command, so i put extra on intent ("kill") and check it in lockscreen.java.. this lockscreen.java can check the extra intent and can display a toast "extra accepted" but can close the lockscreen activity with finish()..

my assumption is for now that Intent.FLAG_ACTIVITY_NEW_TASK is duplicating a locksreen activity.. so it will create a double lockscreen activity and the finish method is closing another lockscreen.java that started by Intent.FLAG_ACTIVITY_NEW_TASK.. that's only assumption.. am i wrong?? please correct me..

has anyone know how to solve my problem?? i'm really want the "andro-unlock" command can close the lockscreen activity and need it works for my college final project.. please help..

regards,

michael..



from How to close this activity? (Android)

No comments:

Post a Comment