finish()函数不会终止活动。活动再次收到oncreate事件

时间:2018-03-13 03:15:45

标签: android galaxy activity-lifecycle

当Activity收到onCreate事件时,我运行MxPlayer。 当MxPlayer退出时,它会在onActivityResult上完成Activity。

finish()函数不会终止活动。 我在Galaxy Note 8(Android 7.1.1)上找到了。

正常情况:

onCreate - onStart - onResume - onPause - 授予权限 - onStop - onActivityResult(完成) - onStop - onDestroy

异常案例:三星Galaxy Note 8

onCreate - onStart - onResume - onPause - 授予权限 - onStop - onActivityResult(完成) - onCreate - onStart - onResume - onPause - onStop - onDestroy

活动发布源代码。

package example.mobile;
import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import com.gun0912.tedpermission.PermissionListener;
import com.gun0912.tedpermission.TedPermission;
import java.util.ArrayList;

public class ExamActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LOG.d(getApplicationContext(), "Activity onCreate");

        setContentView(R.layout.activity_streaming);

    }

    @Override
    protected void onRestart() {
        LOG.d(getApplicationContext(), "Activity onRestart");
        super.onRestart();
    }

    @Override
    protected void onStart() {
        LOG.d(getApplicationContext(), "Activity onStart");


        // permission  https://github.com/ParkSangGwon/TedPermission
        // compile 'gun0912.ted:tedpermission:2.1.0'
        TedPermission.with(this)
                .setPermissionListener(permissionlistener)
                .setDeniedMessage(R.string.permission_againg_request)
                .setPermissions(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .check();
        super.onStart();
    }

    PermissionListener permissionlistener = new PermissionListener() {
        @Override
        public void onPermissionGranted() {
            LOG.d(getApplication(), "Permission Granted");

            String packageName = "com.mxtech.videoplayer.ad";
            String url = "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8";

            Intent intent = new Intent(Intent.ACTION_VIEW);
            Uri videoUri = Uri.parse(url);
            intent.setDataAndType( videoUri, "video/*" );
            intent.setPackage(packageName);
            startActivityForResult(intent, 1);
        }

        @Override
        public void onPermissionDenied(ArrayList<String> deniedPermissions) {
            LOG.d(getApplication(), "Permission Denied");
        }

    };
    @Override
    protected  void onResume() {
        LOG.d(getApplicationContext(), "Activity onResume");
        super.onResume();
    }

    @Override
    protected  void onPause() {
        LOG.d(getApplicationContext(), "Activity onPause");
        super.onPause();
    }

    @Override
    protected void onStop() {
        LOG.d(getApplicationContext(), "Activity onStop");
        super.onStop();
    }

    @Override
    protected void onDestroy() {

        LOG.d(getApplicationContext(), "Activity onDestroy");

        super.onDestroy();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        LOG.d(getApplication(), "keyCode=" + keyCode);
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if(requestCode == 1 ) {

            LOG.d(getApplication(), String.format("onActivityResult. close step"));

            finish();

        }

        super.onActivityResult(requestCode, resultCode, data);
    }


}

0 个答案:

没有答案