[英]Android startActivity not working
I'm having small problem with my app. 我的应用程序有小问题。
startActivity(Intent intent)
is not working. startActivity(Intent intent)
不起作用。
switch (id) {
case R.id.action_add:
if (auth.getCurrentUser() != null) {
if (vf.getDisplayedChild() > 0 && vf.getDisplayedChild() < 3) {
Intent intent = new Intent(MainActivity.this, SubmitActivity.class);
intent.putExtra("category", vf.getDisplayedChild());
startActivity(intent);
Toast.makeText(this, "You are about to create record", Toast.LENGTH_SHORT).show();
}
}
break;
case R.id.action_save:
saveList("monuments", monument_data);
saveList("ski_resorts", ski_data);
Toast.makeText(this, "Data saved for offline use", Toast.LENGTH_SHORT).show();
break;
}
Actually, someone should simply tell that statement's condition wasn't meeted but in fact, toast after startActivity
is shown so statement is correct. 实际上,应该只说出不满足该语句的条件,但实际上,在显示
startActivity
之后的祝酒词是正确的。 I have intent also in recyclerview's adapter on framelayout
is clicked but here intent doesn't work also. 我也有意在单击
framelayout
上的recyclerview的适配器,但是这里的意向也不起作用。
I could also mention that I have intent with shared object animation(not the same intent). 我还可以提到我有共享对象动画的意图(不是相同的意图)。
Anyone knows what is wrong? 有人知道怎么了吗? Intent in switch statement(shown above) worked until I added intent into recyclerview, Please help.
切换语句中的意图(如上所示)一直有效,直到我将意图添加到recyclerview中,请帮助。
EditActivity: EditActivity:
public class EditActivity extends AppCompatActivity {
FirebaseAuth auth;
DatabaseReference ref, target;
StorageReference storage;
ProgressDialog dialog;
@BindView(R.id.imageView8)
ImageView main_image;
@BindView(R.id.input_title)
EditText title;
@BindView(R.id.input_desc)
EditText desc;
@BindView(R.id.input_location)
EditText location;
@BindView(R.id.switch1)
Switch isPublic;
@BindView(R.id.switch2)
Switch isFree;
@BindView(R.id.input_price)
EditText price;
@BindView(R.id.button3)
Button send;
public static final int PICK_IMAGE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit);
ButterKnife.bind(this); . . . }}
SubmitActivity: SubmitActivity:
public class SubmitActivity extends AppCompatActivity {
FirebaseAuth auth;
DatabaseReference ref, target;
StorageReference storage;
ProgressDialog dialog;
@BindView(R.id.imageView8)
ImageView main_image;
@BindView(R.id.input_title)
EditText title;
@BindView(R.id.input_desc)
EditText desc;
@BindView(R.id.input_location)
EditText location;
@BindView(R.id.switch1)
Switch isPublic;
@BindView(R.id.switch2)
Switch isFree;
@BindView(R.id.input_price)
EditText price;
@BindView(R.id.button3)
Button send;
public static final int PICK_IMAGE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_submit);
ButterKnife.bind(this); . . . }}
This part filtered with "intent" appear when option is selected: 选择选项时,将显示用“意图”过滤的部分:
01-11 18:37:13.918 22224-22239/?
01-11 18:37:13.918 22224-22239 /? I/ActivityManager: START u0 {flg=0x8000 cmp=com.ready.slovakia/.SubmitActivity (has extras)} from uid 10883 on display 0 01-11 18:37:14.122 22224-22251/?
I / ActivityManager:从显示屏上的uid 10883开始u0 {flg = 0x8000 cmp = com.ready.slovakia / .SubmitActivity /(具有附加功能)} 0 01-11 18:37:14.122 22224-22251 /? I/WindowManager: Gaining focus: Window{8f13679 u0 com.ready.slovakia/com.ready.slovakia.MainActivity}
I / WindowManager:获得焦点:Window {8f13679 u0 com.ready.slovakia / com.ready.slovakia.MainActivity}
As per our discussion on chat and the debugging, here's the issue: 根据我们关于聊天和调试的讨论,这是问题所在:
You SubmitActivity.java
has if (auth.getCurrentUser() != null) finish();
您
SubmitActivity.java
具有if (auth.getCurrentUser() != null) finish();
on line 78, which finishes the activity when the user is authenticated and logged in. It should be if (auth.getCurrentUser() == null) finish();
在第78行,该行完成了对用户进行身份验证和登录后的活动。应该是
if (auth.getCurrentUser() == null) finish();
instead. 代替。
But ideally, this issue will not arise because you are checking the same condition on line 390 of MainActivity.java
, which will prevent intent from getting SubmitActivity
started when the user is not logged in. 但是理想情况下,不会出现此问题,因为您正在检查
MainActivity.java
390行上的相同条件,这将防止意图在用户未登录时启动SubmitActivity
。
Please check your layout in the SubmitActivity
. 请在
SubmitActivity
检查您的布局。 Do you set the content via: setContentView()
? 是否通过
setContentView()
设置内容? Most probably your activity is started but nothing is displayed so it's invisible. 您的活动很可能已经开始,但是什么也不显示,因此它是不可见的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.