I have an app where there are some screens that are made in Flutter (add2app). I have a class called CMFlutterActivity that is a subclass of io.flutter.embedding.android.FlutterActivity. I use this class to manage the method channels, but I am not too happy with how the screen is presented, because the first Flutter frame is not available when the Activity is presented. After some research I figured there is a method in the FlutterActivity that I can override to know when the first Flutter frame is available, it is called onFlutterUiDisplayed. The problem I have is: how do I manage to only make the Activity visible after this method has been called? Has anyone solved this problem already?
I am currently starting the activity in the following manner:
startActivity(Intent(context, CMFlutterActivity::class.java))
Here are some of my configurations:
AndroidManifest.xml:
<activity
android:name=".ui.flutter.CMFlutterActivity"
android:theme="#style/AppTheme.NoFullscreen"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="portrait"
android:stateNotNeeded="true"
android:exported="true"
/>
styles.xml:
<style name="AppTheme.NoFullscreen">
<item name="android:windowFullscreen">false</item>
</style>
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
it keeps says me that
requires your app to be migrated to the Android embedding v2. Follow the steps on
https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects
Note....its the same as following this steps
https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects
but i made it easier for any one that cant follow the steps .....hope that helped.
After trying multiple ways to deal with the situation,
I ended up with a good enough solution
just open this files in your project and copy >> paste this lines of code and it will work .......make sure to delete all lines of code in your this files and replace it to this new ones.
1: MainActivity.java
package co.appbrewery.flash_chat;
import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterActivity {
}
2: styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
</resources>
3: AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.appbrewery.flash_chat">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application android:label="flash_chat" android:icon="#mipmap/ic_launcher">
<activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="#style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in #style/LaunchTheme). -->
<meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="#drawable/launch_background" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data android:name="flutterEmbedding" android:value="2" />
</application>
</manifest>
Follow the steps. Hopefully, your problem will be solved. https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects
I am using the flutter_facebook_login package to login the app. This method shows a login progress bar everytime I login. I want to remove that progress bar and use my own progress indicator.
How can I do that?
I already have a working progress bar and have used it. All i want is to remove the progress indicator of flutter_facebook_plugin.
I used a method where i tweaked the AndroidManifest.xml file. but it didn't work.
AndroidManifest.xml
<activity
android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:theme="#style/LaunchTheme" />
styles.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:progressBarStyle">#style/InvisibleProgress</item>
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
<style name="InvisibleProgress">
<item name="android:visibility">gone</item>
</style>
</resources>
Solution for Android is available here,
works fine for Flutter plugin also
Android: How to hide progress circle in Facebook login
I have an app with Ionic 3 and in your app.component.ts, i using the Statusbar ionic plugin to hide that, but, this occurs only after platform ready is fired.
How do i hide that during splashscreen? I tried:
– Not hide during splashscreen, only after this hide
– Not change background color during splashscreen
Solutions?
Android
It seems that there is not elegant way to hide statusbar on app launch.
But there is an way to do that.
Find MainActivity.java (maybe platforms/android/src/io/ionic/starter)
Add the below code
import android.view.WindowManager;
public class MainActivity extends CordovaActivity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// enable Cordova apps to be started in the background
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
moveTaskToBack(true);
}
// [Hyuck] add this two line below
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
}
// [Hyuck] onStart() is totally new.
#Override
public void onStart()
{
super.onStart();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
}
IOS
I can only test Android device. So, I just leave the link which may solve your issue
After addition of your code in MainActivity page
I run the command to build apk
I got this error
Task :app:compileDebugJavaWithJavac FAILED
E:\Ionic\AIOU_Solutions1\platforms\android\app\src\main\java\io\ionic\starter\MainActivity.java:38: error: package WindowManager does not exist
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
I got the same problem with a Cordova based app. I couldn't figure out how to hide the status bar during the Splashcreen (tried many things) until I found this solution.
Hide status bar during splashcreen
Option 1 - Edit files yourself
Find the file platforms/android/app/src/main/res/values/strings.xml
Add a custom theme with specific rules by editing the XML
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="app_name">My App Name</string>
<string name="launcher_name">#string/app_name</string>
<string name="activity_name">#string/launcher_name</string>
<!-- Add your custom theme rules -->
<style name="MyCustomTheme" parent="#style/Theme.AppCompat.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
Find the file platforms/android/app/src/main/AndroidManifest.xml
Find the <activity> tag and add the reference to "MyCustomTheme"
<activity android:theme="#style/MyCustomTheme" ...etc...
Option 2 - Edit files from the Cordova config.xml
You may prefer to manage this custom theme directly from your config.xml file without having to edit yourself the AndroidManifest.xml and strings.xml. It can be helpful in case of cordova platform remove android and cordova platform add android which will delete your changes.
Add this in your config.xml
<platform name="android">
<!-- Edit the activity tag fo your AndroidManifest.xml -->
<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application/activity">
<activity android:theme="#style/MyCustomTheme"/>
</edit-config>
<!-- Edit the strings.xml file -->
<edit-config file="strings.xml" mode="add" target="/resources">
<style name="MyCustomTheme" parent="#style/Theme.AppCompat.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
</edit-config>
</platform>
Last step, remember that for being able of using <edit-config> tag from your config.xml file, you need to add this xmlns attribute to your <widget> tag.
<?xml version='1.0' encoding='utf-8'?>
<widget xmlns:android="http://schemas.android.com/apk/res/android" ...etc...
If you have better options, I'm curious to heard about it!
Scenario : I have a simple to-do app where In the main activity I have a fragment that takes a list of to-dos from the user. I set an alarm for a fixed time in the future (in my case every 2 min ONLY for testing. The AlarmReceiver class launches an AlarmActivity which shows the list of to-dos as checkboxes for the user to mark as done.
When the alarm comes up and shows the list, I have a "Submit" button to mark all the checked items as 'done' in the local db.
Problem:
This AlarmActivity disappears on click of submit since I'm calling finish on it. But when I launch the app from the icon, the AlarmActivity is shown instead of the main activity.
AlarmReceiver code :
final Intent intent1 = new Intent(context, CheckListAlarmActivity.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NO_HISTORY);
context.startActivity(intent1);
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:noHistory="true"
android:clearTaskOnLaunch="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AlarmActivity"
android:alwaysRetainTaskState="false"
android:clearTaskOnLaunch="true"
android:showOnLockScreen="true"
android:screenOrientation="sensorPortrait"
android:noHistory="true"/>
<receiver android:name=".AlarmReceiver" />
</application>
I added the android:clearTaskOnLaunch="true" and that seems to do the trick sometimes but not always.
And in the background when I put the loggers, it shows that every time I launch using the app icon it calls the onCreate of the MainActivity and then immediately calls the onCreate of the AlarmActivity.
I have tried looking for all kinds of solutions and tried setting a bunch of flags to the Intent. Nothing seems to do the trick convincingly.
It seems like a simple problem but I am not able to find the solution. Any help/guidance would be appreciated.
I lock the device screen, start the activity LockAct. LockAct starts another activity which has a SurfaceView.
If I don't add <item name="android:windowBackground">#android:color/transparent</item> to the activity with the SurfaceView, neither surfaceCreated nor surfaceChanged will be called.
If I add <item name="android:windowBackground">#android:color/transparent</item> to the activity with the SurfaceView, LockAct disappears and slides in on Android 5.0 only as shown in the video. It looks ugly.
How to prevent LockAct from disappearing and sliding in again?
What I've already tried:
ActivityOptions for LockAct
Intent intent = new Intent(getApplicationContext(), LockAct.class);
startActivity(intent, ActivityOptions.makeCustomAnimation(getApplicationContext(), 0, 0).toBundle());
android:windowAnimationStyle for LockAct
<style name="NoAnim" parent="#style/AppTheme">
<item name="android:windowAnimationStyle">#null</item>
</style>
<activity android:name="com.admin.LockAct"
android:theme="#style/NoAnim" />
android:windowEnterTransition and android:windowExitTransition for LockAct
<style name="NoAnim" parent="#style/AppTheme">
<item name="android:windowEnterTransition">#null</item>
<item name="android:windowExitTransition">#null</item>
</style>
<activity android:name="com.admin.LockAct"
android:theme="#style/NoAnim" />
Here is an archive with my sample Android app: https://www.dropbox.com/s/mc4pzqwc2o8lsej/Sample-Android-Lock.rar?dl=0
Activities are not started or finished smoothly when the device screen is locked. I noticed that on Android 5.0, but everything looks pretty good on my Samsung Galaxy S3 with CyanogenMod (Android 4.3.1). So different behavior may be on different devices and/or OS versions.
A co-worker gave me the link https://stackoverflow.com/a/23022023/1065835, and I'm going to use fragments instead of activities.