How to navigate to a specific flutter route from an Android activity?(如何从 Android 活动导航到特定的颤振路线?)
问题描述
我有一个现有的 android 应用程序,我已经在我的项目中集成了颤振我想调用一个颤振特定的路线,我在我的主要方法中定义这样的路线
I have an existing android application and i have integrated flutter in my project i want to call a flutter specific route which i define in my main method like this
class FlutterView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Platform View',
initialRoute: '/',
routes: {
'/': (context) => HomeScreen(),
'/secound': (context) => MyCustomForm(),
'/dashboard': (context) => DashBoardScreen(),
'/login': (context) => LoginScreen(),
},
theme: new ThemeData(
primarySwatch: Colors.red,
textSelectionColor: Colors.red,
textSelectionHandleColor: Colors.red,
),
);
}
}
从我的 android 活动中,我正在调用这样的颤动活动
from my android activity i am calling flutter activity like this
startActivity(new Intent(this,FlutterActivity.class));
startActivity(new Intent(this,FlutterActivity.class));
它确实打开了我的颤动活动,但使用 initialRoute: '/' 这很好,但有时我想打开例如('/dashboard')路线,当我打开颤动活动时我该怎么做??
it does open my flutter activity but with the initialRoute: '/' which is fine but some time i want to open for eg( '/dashboard') routes when i open a flutter activity how can i do it ??
推荐答案
来自 Android,如上所述 这里:
From Android, as stated here:
Intent intent = new Intent(context, MainActivity.class);
intent.setAction(Intent.ACTION_RUN);
intent.putExtra("route", "/routeName");
context.startActivity(intent);
来自 Flutter,使用 android_intent
:
From Flutter, using android_intent
:
AndroidIntent intent = AndroidIntent(
action: 'android.intent.action.RUN',
// Replace this by your package name.
package: 'app.example',
// Replace this by your package name followed by the activity you want to open.
// The default activity provided by Flutter is MainActivity, but you can check
// this in AndroidManifest.xml.
componentName: 'app.example.MainActivity',
// Replace "routeName" by the route you want to open. Don't forget the "/".
arguments: {'route': '/routeName'},
);
await intent.launch();
请注意,应用程序只有在终止时才会在此路由中打开,也就是说,如果应用程序处于前台或后台,则不会在指定的路由中打开.
Notice that the app is going to open in this route only if it's terminated, that is, in case the app is in foreground or background, it won't open in the specified route.
这篇关于如何从 Android 活动导航到特定的颤振路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 Android 活动导航到特定的颤振路线?
- Android - 拆分 Drawable 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01