简体   繁体   English

执行停止未恢复的活动 - Android

[英]Performing stop of activity that is not resumed - Android

I am getting this error: Performing stop of activity that is not resumed LoginActivity. 我收到此错误:执行停止未恢复LoginActivity的活动。 I have read the other threads about this error but I still can`t see what is the problem. 我已经阅读了有关此错误的其他主题,但我仍然无法看到问题所在。

Here is my Logcat: 这是我的Logcat:

  java.lang.RuntimeException: Performing stop of activity that is not resumed: {package/package.LoginActivity}
        at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3333)
        at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3420)
        at android.app.ActivityThread.access$1200(ActivityThread.java:161)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:157)
        at android.app.ActivityThread.main(ActivityThread.java:5356)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
        at dalvik.system.NativeStart.main(Native Method)

And my Activity: 我的活动:

public class LoginActivity extends Activity {
 EditText edtMail,edtPass;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    Button regButton = (Button) findViewById(R.id.registerbtn);
    Button logButton = (Button) findViewById(R.id.login);

    final Context context = getApplicationContext();
    edtMail = (EditText) findViewById(R.id.email);
    edtPass = (EditText) findViewById(R.id.pword);
    // testing if GooglePlayServices works//TODO
    if(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) ==  ConnectionResult.SUCCESS )
        System.out.println("Google PLAY SERVICES");


    //getting specs for device //TODO
    HashMap<String, String> specsHash = new HashMap<String, String>();
    GetSpecs getSpecs = new GetSpecs(this);
    specsHash = getSpecs.getAllSpecs();
    for (Map.Entry<String,String> entry : specsHash.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        System.out.println(key + " = " + value);
    }


    //check device camera
    boolean hasCamera = CheckDeviceCamera.isDeviceSupportCamera(context);

    //check device GPS
    boolean hasGPS = CheckDeviceGPS.isDeviceSupportGPS(context);

    //if have details try to log the user in
    if (new SharedPrefsMemo().getPrefs(context) == 1) {
        DatabaseConnector databaseConnector = new DatabaseConnector(context);
        //gasire: 0->nimic gasit, 1->gasit agent; 2->gasit asistent
        int gasire = databaseConnector.loadInregistrare(Prefs.emailPref, Prefs.parolaPref);
        if (gasire != 0) {
            Intent myIntent = new Intent(LoginActivity.this, MainActivity.class);
            myIntent.putExtra("tip", gasire);
            startActivity(myIntent);
        }
    }


    //register button
    regButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(context, RegisterSplitActivity.class);
            startActivity(intent);
        }
    });

    logButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            String password = edtPass.getText().toString();
            String email = edtMail.getText().toString();

            DatabaseConnector databaseConnector = new DatabaseConnector(context);

            int gasire = databaseConnector.loadInregistrare(email, password);
            if(gasire != 0 ) {
                SharedPrefsMemo sharedPrefsMemo = new SharedPrefsMemo();

                if(gasire == 1) {
                    sharedPrefsMemo.memoPrefs(GetObiecte.agent.email, GetObiecte.agent.parola, GetObiecte.agent.id,
                                             context);
                    Intent myIntent = new Intent(LoginActivity.this, MainActivity.class);
                    myIntent.putExtra("tip", gasire);
                    startActivity(myIntent);

                }

                else
                    if(gasire == 2) {
                        sharedPrefsMemo.memoPrefs(GetObiecte.asistent.email, GetObiecte.asistent.parola,
                                                    GetObiecte.asistent.id, context);
                        Intent myIntent = new Intent(LoginActivity.this, MainActivity.class);
                        myIntent.putExtra("tip", gasire);
                        startActivity(myIntent);

                    }


            }
           else  {
                CharSequence text = "Date de logare gresite!";
                int duration = Toast.LENGTH_LONG;
                Toast toast = Toast.makeText(context, text, duration);
                toast.show();
            }
        }
    });

}

@Override
protected void onResume() {
    super.onResume();
    //activare GPS//TODO
    LocationManager locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
    if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        //Ask the user to enable GPS
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Location Manager");
        builder.setMessage("Activate GPS?");
        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //Launch settings, allowing user to make a change
                Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivity(i);
            }
        });
        builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //No location service, no Activity
                int duration = Toast.LENGTH_LONG;
                Toast toast = Toast.makeText(LoginActivity.this, "Activate the GPS", duration);
                toast.show();
                finish();
            }
        });
        builder.create().show();
    }
}

}

I had the same problem and the answer by @sheetal solved my issue. 我有同样的问题,@ sheetal的答案解决了我的问题。

https://stackoverflow.com/a/23246159/4871489 https://stackoverflow.com/a/23246159/4871489

The issue will still be there on all HighEnd phones with 4.4.2 and above including NEXUS 5,Samsumg s4 since onResume gets called but still it is in animation stage.So if you try to start a activity in onResume the issue will replicate. 问题仍然存在于4.4.2及以上的所有HighEnd手机上,包括NEXUS 5,Samsumg s4,因为onResume被调用但仍处于动画阶段。所以如果你尝试在onResume上启动一个活动,问题就会复制。

I created a handler to start my intent with a small delay and the issue disappeared. 我创建了一个处理程序以稍微延迟启动我的意图,问题就消失了。

Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM