【发布时间】:2014-02-20 09:42:13
【问题描述】:
当用户触摸 AlertDialog 内的 OK 按钮时,我一直在尝试让我的应用返回主 Activity。
我显示的警报对话框基本上是一条错误消息,通知用户在他们选择的特定日期没有找到数据,并在一个不是主要活动的活动中调用,但我希望它们在以下情况下发送回主要活动他们点击确定。
调用运行良好,只是它似乎不知道如何找到主活动,即使我正在使用的调用在任何正常活动中都有效。
我得到的error是:
1554-1554/org.springframework.android.showcase2 E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=org.springframework.android.showcase2.MainActivity }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
具体的AlertDialog代码是:
package org.springframework.android.showcase2;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MyAlertDialogFragment extends DialogFragment {
private String title;
private String message;
private TextView tvError;
public MyAlertDialogFragment(String sTitle, String sMessage){
this.title = sTitle;
this.message = sMessage;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setTitle(this.title)
.setMessage(this.message)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// This is the way I nomally call a new activity inside other activities but seems to not work inside this AlertDialog scope
Intent i = new Intent("org.springframework.android.showcase2.MainActivity");
startActivity(i);
}
}
)
.create();
}
}
【问题讨论】:
-
你在 AndroidManifest.xml 中定义了
org.springframework.android.showcase2.MainActivity吗? -
试试“MyAlertDialogFragment.this.getActivity().startActivity(i)”
-
是的 MainActivity 在 Manifest 中
标签: android android-activity android-alertdialog