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 活动导航到特定的颤振路线?
基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
