正在停止未恢复的活动-Android
我遇到了这个错误:正在停止未恢复LoginActivity的活动。我已经阅读了其他关于这个错误的文章,但是我仍然看不出问题出在哪里 这是我的日志:正在停止未恢复的活动-Android,android,android-lifecycle,Android,Android Lifecycle,我遇到了这个错误:正在停止未恢复LoginActivity的活动。我已经阅读了其他关于这个错误的文章,但是我仍然看不出问题出在哪里 这是我的日志: java.lang.RuntimeException: Performing stop of activity that is not resumed: {package/package.LoginActivity} at android.app.ActivityThread.performStopActivityInner(Ac
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)
我的活动:
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();
}
}
}
公共类LoginActivity扩展活动{
编辑文本edtMail,edtPass;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u登录);
按钮regButton=(按钮)findViewById(R.id.registerbtn);
按钮logButton=(按钮)findViewById(R.id.login);
最终上下文=getApplicationContext();
edtMail=(EditText)findViewById(R.id.email);
edtPass=(EditText)findViewById(R.id.pword);
//测试GooglePlayServices是否有效//待办事项
if(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this)=ConnectionResult.SUCCESS)
System.out.println(“谷歌播放服务”);
//获取设备//待办事项的规格
HashMap specsHash=新的HashMap();
GetSpecs GetSpecs=新的GetSpecs(此);
specsHash=getSpecs.getAllSpecs();
对于(Map.Entry:specsHash.entrySet()){
String key=entry.getKey();
字符串值=entry.getValue();
System.out.println(键+“=”+值);
}
//检查设备摄像机
布尔值hasCamera=CheckDeviceCamera.isDeviceSupportCamera(上下文);
//检查设备GPS
布尔值hasGPS=CheckDeviceGPS.isDeviceSupportGPS(上下文);
//如果有详细信息,请尝试登录用户
如果(新的SharedPrefsMemo().getPrefs(上下文)==1){
DatabaseConnector DatabaseConnector=新的DatabaseConnector(上下文);
//煤气:0->nimic煤气,1->煤气代理;2->煤气辅助
int gasire=databaseConnector.loadInregistrare(Prefs.emailPref,Prefs.parolaPref);
如果(气体!=0){
Intent myIntent=newintent(LoginActivity.this,MainActivity.class);
myIntent.putExtra(“小费”,汽油);
星触觉(myIntent);
}
}
//注册按钮
regButton.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
Intent Intent=新的Intent(上下文,registerSplitivity.class);
星触觉(意向);
}
});
logButton.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
字符串密码=edtPass.getText().toString();
字符串email=edtMail.getText().toString();
DatabaseConnector DatabaseConnector=新的DatabaseConnector(上下文);
int gasire=databaseConnector.loadInregistrare(电子邮件、密码);
如果(气体!=0){
SharedPrefsemo SharedPrefsemo=新SharedPrefsemo();
如果(气体==1){
SharedPrefsMemoPrefs(getobecte.agent.email、getobecte.agent.parola、getobecte.agent.id、,
上下文);
Intent myIntent=newintent(LoginActivity.this,MainActivity.class);
myIntent.putExtra(“小费”,汽油);
星触觉(myIntent);
}
其他的
如果(气体==2){
SharedPrefsemo.memoPrefs(getobecte.asistent.email、getobecte.asistent.parola、,
getobecte.asistent.id,上下文);
Intent myIntent=newintent(LoginActivity.this,MainActivity.class);
myIntent.putExtra(“小费”,汽油);
星触觉(myIntent);
}
}
否则{
CharSequence text=“登录日期gresite!”;
int duration=Toast.LENGTH\u LONG;
Toast Toast=Toast.makeText(上下文、文本、持续时间);
toast.show();
}
}
});
}
@凌驾
受保护的void onResume(){
super.onResume();
//activare全球定位系统//待办事项
LocationManager LocationManager=(LocationManager)this.getSystemService(Context.LOCATION\u服务);
如果(!locationManager.isProviderEnabled(locationManager.GPS\U提供程序)){
//要求用户启用GPS
AlertDialog.Builder=新建AlertDialog.Builder(此);
建造商名称(“位置经理”);
builder.setMessage(“激活GPS?”);
builder.setPositiveButton(“是”,新建DialogInterface.OnClickListener(){
@凌驾
public void onClick(DialogInterface dialog,int which){
//启动设置,允许用户进行更改
意图i=新意图(设置、动作、位置、来源、设置);
星触觉(i);
}
});
setNegativeButton(“否”,新的DialogInterface.OnClickListener(){
@凌驾
public void onClick(DialogInterface dialog,int which){
//没有定位服务,没有活动
int duration=Toast.LENGTH\u LONG;
Toast Toast=Toast.makeText(LoginActivity.this,“激活GPS”,持续时间);
toast.show();
完成();
}
});
builder.create().show();
}
}
}
我也遇到了同样的问题,@sheetal的答案解决了我的问题
这一问题仍然存在于所有4.4.2和
上面包括Nexus5,SamsumgS4,因为onResume被调用,但是
但它仍处于动画阶段。所以,如果您尝试在中启动活动
一旦恢复,问题将重复
我创建了一个处理程序来启动我的意图,只需一点延迟,问题就消失了
希望它有帮助试着评论一下结尾();在简历中。。然后运行并查看它是否仍然给出错误/通过注释finish()在方法onCreate()而不是onResume()中编写GPS启用的代码。很好。谢谢这似乎是一个更高层次的问题