如何从 Android 活动导航到特定的颤振路线?

How to navigate to a specific flutter route from an Android activity?(如何从 Android 活动导航到特定的颤振路线?)

本文介绍了如何从 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 活动导航到特定的颤振路线?