0

I'm working on an existing project for adding a Lock screen for the user to enter the code. After verifying the code the Lock Screen will dismiss and the user can use the app normally. Thank you. I'm not an Android developer so it is very difficult for me. The project is coded in Kotlin and Java.

///mainapp is in Kotlin

package com.mainapp.view.activity

open class BaseActivity: AppCompatActivity() {
    lateinit var repository: BasicRepository

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        pref = PreferenceManager(this)
        setupContentWindow()
    }

    fun setupContentWindow() {
        Helper.handleStatusBar(window, false, this)
    }

    override fun onResume() {
        super.onResume()
        if (requireCode()) {
            val intent = EnterCodeActivity.intent(this, true)
            startActivity(intent)

        } else {
             val intent = Intent(this, EnterCodeActivity::class.java)
             startActivityForResult(intent, Helper.REQUEST_CODE)
        }
    }

///lockscreen is in java

package com.lockscreen.activity;

public class EnterCodeActivity extends AppCompatActivity {
public static Intent intent(Context context, boolean requireCode) {
        Intent intent = new Intent(context, EnterPinActivity.class);
        intent.putExtra("REQUIRE_CODE", requireCode);
        return intent;
    }

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_enterpin);
       
        final CodeLockListener codeLockListener = new CodeLockListener() {

            @Override
            public void onComplete(String code) {
              checkCode(code);
            }

            @Override
            public void onEmpty() {
                Log.d(TAG, "Code empty");
            }
        };

        mCodeLockView = (CodeLockView) findViewById(R.id.codelockView);
        mIndicators = (Indicators) findViewById(R.id.indicators);

        mCodeLockView.attachIndicators(mIndicators);
        mCodeLockView.setCodeLockListener(codeLockListener);
        mIndicators.setIndicatorType(Indicators.IndicatorType.FILL_WITH_ANIMATION);
    }

private void checkCode(String code) {
     APIManager.getInstance().verifyAuth(code, new Callback<String>() {
           @Override
           public void onResponse(Call<String> call, Response<String> response) {
               if (response.code() == 200) {
                   setResult(RESULT_OK);
                   finish();
                   //dismiss the code lock view after verify the code
 
               } else {
                   mTextTitle.setText("Incorrect Code!")
               }
           }

           @Override
           public void onFailure(Call<String> call, Throwable t) {
               mTextTitle.setText("Incorrect Code!")
           }
       });
   }
14079_Z
  • 401
  • 5
  • 20
  • 3
    It seems calling `finish()` should already dismiss `EnterCodeActivity`... Or, can you help to update what is this currently code do? – Putra Nugraha Oct 06 '21 at 02:25
  • I clean the build and ran it again now it is working. Don't know why it didn't work before. Thanks! – 14079_Z Oct 06 '21 at 23:18

2 Answers2

0

A possible fix would be to add a return statement after calling the finish() method so the execution for the current method will stop there.

Also if you want to get more info check out this thread: How does Activity.finish() work in Android?

MihaiBC
  • 472
  • 5
  • 15
0

I clean the build and ran it again now it is working.

14079_Z
  • 401
  • 5
  • 20