Skip to content

[quick_action][android] Not working with "LauncherActivity" #152883

@peixinli

Description

@peixinli

Copied from internal bug b/357028168

Steps to reproduce

Launched from shortcut

Expected results

Expected: Launching from quick action shortcut should always trigger the callback in quickActions.initialize.

Actual results

Actual: When the app has an "LauncherActivity" which forwards intents to the "MainActivity". (See attached recording)

  1. If the app is launched normally from launch icon, the following shortcut works fine.

  2. if the app is launched from shortcut, only the first shortcut works, the following shortcut is not working.

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:quick_actions/quick_actions.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(useMaterial3: false),
      title: 'Flutter Demo',
      home: MyHomePage(),
    );
  }
}

// Copied from https://pub.dev/packages/quick_actions/example.
class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String shortcut = 'no action set';

  @override
  void initState() {
    super.initState();

    const QuickActions quickActions = QuickActions();
    quickActions.initialize((String shortcutType) {
      setState(() {
        shortcut = shortcutType;
      });
    });

    quickActions.setShortcutItems(<ShortcutItem>[
      // NOTE: This first action icon will only work on iOS.
      // In a real world project keep the same file name for both platforms.
      const ShortcutItem(
        type: 'action_one',
        localizedTitle: 'Action one',
        icon: 'AppIcon',
      ),
      // NOTE: This second action icon will only work on Android.
      // In a real world project keep the same file name for both platforms.
      const ShortcutItem(
          type: 'action_two',
          localizedTitle: 'Action two',
          icon: 'ic_launcher'),
    ]).then((void _) {
      setState(() {
        if (shortcut == 'no action set') {
          shortcut = 'actions ready';
        }
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(shortcut),
      ),
      body: const Center(
        child: Text('On home screen, long press the app icon to '
            'get Action one or Action two options. Tapping on that action should  '
            'set the toolbar title.'),
      ),
    );
  }
}

AndroidManifest.xml

<activity
        android:name=".LauncherActivity"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:exported="true"
        android:hardwareAccelerated="true"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:windowSoftInputMode="adjustResize">

LauncherActivity.java

public final class LauncherActivity extends Activity {

  private static final String QUICK_ACTIONS_EXTRA = "some unique action key";

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent mainActivityIntent = new Intent(this, MainActivity.class);
    mainActivityIntent.putExtras(getIntent());
    startActivity(mainActivityIntent);
    finish();
  }

  @Override
  public void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
  }
}
screen-20240802-165337.1.mov

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listfound in release: 3.24Found to occur in 3.24has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: quick_actionsQuickActions pluginpackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions