Android启动活动显示错误
当我开发android应用程序时。我想按程序打电话。论使用Android启动活动显示错误,android,android-activity,android-framelayout,android-phone-call,Android,Android Activity,Android Framelayout,Android Phone Call,当我开发android应用程序时。我想按程序打电话。论使用 Uri number = Uri.parse("tel:123456789"); Intent callIntent = new Intent(Intent.ACTION_DIAL, number); getContext().startActivity(callIntent); 它显示了一个错误。我使用的是框架布局而不是活动 android.util.AndroidRuntimeException: Calling startAct
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
getContext().startActivity(callIntent);
它显示了一个错误。我使用的是框架布局而不是活动
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ContextImpl.startActivity(ContextImpl.java:1366)
at android.app.ContextImpl.startActivity(ContextImpl.java:1353)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:322)
at com.happiness.lockscreenlibrary.view.LockView$1.onDrag(LockView.java:163)
at android.view.View.dispatchDragEvent(View.java:18339)
at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1492)
at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1478)
at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1478)
at android.view.ViewRootImpl.handleDragEvent(ViewRootImpl.java:5143)
at android.view.ViewRootImpl.access$700(ViewRootImpl.java:108)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3331)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
我使用了context.getApplicationContext().startActivity(CallContent)代码>或上下文。起始触觉(callIntent)代码>而不是getContext().startActivity(callIntent)代码>
但它显示了同样的错误。它将如何解决,请帮助我。要从服务开始活动,或者除其他活动外,您必须在意图中添加标志标志活动新任务
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
callIntent .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(callIntent);
要从服务启动活动,或从除其他活动以外的任何地方启动活动,您必须将标志标志\u活动\u新任务
添加到意图中
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
callIntent .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(callIntent);
尝试将标志添加到您的意图中:
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
您的代码将被删除
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(callIntent);
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(callIntent);
希望能帮助你 尝试在您的意图中添加标志:
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
您的代码将被删除
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(callIntent);
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(callIntent);
希望能帮助你 您必须添加设置标志(意图.标志\u活动\u新任务)
如果设置,此活动将成为此服务器上新任务的开始
历史堆栈
您必须添加setFlags(Intent.FLAG\u ACTIVITY\u NEW\u TASK)
如果设置,此活动将成为此服务器上新任务的开始
历史堆栈
您可以在此处获取有关意向标志的信息:
标记\活动\新建\任务如果设置,此活动将成为任务的开始
此历史堆栈上的新任务
您可以在此处获取有关意向标志的信息:
标记\活动\新建\任务如果设置,此活动将成为任务的开始
此历史堆栈上的新任务
您应该使用构造函数将上下文从活动传递到视图
new LockView(this);
使用相同的上下文启动新活动
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
添加Intent.FLAG\u ACTIVITY\u NEW\u TASK
标志以启动新活动。您应该使用构造函数将上下文从活动传递到视图
new LockView(this);
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
使用相同的上下文启动新活动
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
添加Intent.FLAG\u ACTIVITY\u NEW\u TASK
FLAG开始新活动。使用FLAG\u ACTIVITY\u NEW\u TASK调用您的startActivity。
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
logcat指出错误,而您仍将其张贴在
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
callIntent .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(callIntent);
用FLAG\u ACTIVITY\u NEW\u任务调用您的startActivity。
logcat指出错误,而您仍将其张贴在
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
callIntent .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(callIntent);
从活动上下文外部调用startActivity()需要标志\u Activity\u NEW\u TASK标志。
从活动上下文外部调用startActivity()需要标志\u Activity\u NEW\u TASK标志。