I'm using Xamarin Forms to produce a TabbedPage consisting of more ContentPages. This is the part of code causing trouble:
public void launchMainDesign(object s, EventArgs e) {
MainPage = new TabbedPage {
Children = {
new ContentPage {
Title = "Login",
Content = pages.loginContent,
BackgroundImage = "bgmain.jpg"
},
new ContentPage {
Title = "Sign Up",
Content = pages.signUpContent,
BackgroundImage = "bgmain.jpg"
}
}
};
}
It seems absolutely fine. I have both the images in my Drawable directory, with the build action set to "AndroidResource".
Whenever the launchMainDesign() function is fired by pressing a button, the app crashes immediately, both in emulator and a build version of the app on a tablet. Unfortunately, I can't test on iOS and WP.
I even tried putting the whole inside part of the function in a try/catch block and print out the exception, but the app just crashes nevertheless.
I am desperately trying to solve this simple problem for about a week now. No one seems to be having exactly the same issue as me. Weirdest thing is, I have a different app where I use exactly the same method and it works just fine. Can the Android Theme be causing this (I'm using Holo, in the working app, there's no theme specified)? That seems to be the only difference.
I also don't think this is caused by RAM struggles, as the image is only about 700 kilobytes (1080x1920) - for this example, I've only used one image.
It could be a memory issue, because even do the size is not big depending on the device resolution it might be trying to scale the image to the device dimensions.
Try checking this README:
https://github.com/xamarin/customer-success/blob/master/samples/Xamarin.Forms/SliderView/README.md
Explains Xamarin.Forms Android Image Memory Management so could help you get around the issue you might be having.
Related
I am facing an issue with local images in a React Native app. I have a file where I require all of my app icons, something like this:
export const icons = {
a: require("a.png"),
b: require("b.png"),
c: require("c.png")
};
Then I use these files in the React Native Image component. For instance:
import { icons } from "icons";
<Image
source={icons.a}
/>
It works fine in dev mode on both iOS and Android. It also works fine on iOS archive in production. But in Android production bundle, the icons seem to be randomly switched up. Sometimes icon a is displayed instead of icon b, sometimes it is icon c that is displayed instead of icon a, and so on... Sometimes one of the icon is not even displayed at all.
Can the problem come from requiring all the files in the same file ?
I would appreciate any clue. Thanks a lot.
I'm trying to add a custom action to the media session's playback state, so it can show an addition button on Android Auto. The code is indeed simple, the button is added and I can receive its callback, but the problem is the button doesn't have an icon:
The code:
val builder = PlaybackStateCompat.Builder()
builder.addCustomAction(
"ACTION_TEST",
"TEST LABEL",
R.drawable.ic_test // I tried vector drawable, png,... nothing works
)
// ...
mediaSession.setPlaybackState(builder.build())
The result: the added button doesn't have an icon, only shows a ripple effect (the circle in the screenshot) when I click it, otherwise it's invisible.
I found out the root cause. It's because Android Studio auto-optimizes the build process to produce minimal APK that can run on current ADB-connected devices.
In my case, AS included only xhdpi resources in the debug APK, therefore Android Audio HeadUnit couldn't load the drawable. Basically, AS silently changed the Gradle config to somewhat like this:
android {
...
productFlavors {
dev {
resConfigs "xhdpi" // <- root cause
}
...
}
}
I can simply run my app from the terminal to get rid of this problem.
If you have the same problem, just ensure the drawable is available for all screen densities (hdpi, xhdpi,...), and check your APK whether it's packaged with resources in all screen densities.
For me, the problem was resolved when I cleared the data of Android App application on my phone.
Was using it to run DHU emulator on desktop. Somehow its caching went awry.
I'm having issue of missing signout button from the header toolbar in android devices. In simulator and apple device I do see the signout button but not on android tablet/phone. This wasn't the case before 3-4 days. Is there any change in the android build server that causing this issue. This is happening when more than one control in the toolbar. if the toolbar has one control to the right then it displays without any issue. Please let me know if anyone else have same issue.
Android Simulator Screenshot
Android Tablet Screenshot
public static void addSignout(Form f) {
f.getToolbar().addMaterialCommandToRightBar("", FontImage.MATERIAL_LOCK, 6.5f, e -> {
Server.instance.logout();
new LoginForm().show();
});
}
I'm using asset manager to generate my font using object
FreeTypeFontGeneratorLoader, specifically I'm using this current parameter
FreeTypeFontLoaderParameter parameter = new FreeTypeFontLoaderParameter();
parameter.fontFileName = "fonts/myFont.ttf";
parameter.fontParameters.size = size;
parameter.fontParameters.minFilter = Texture.TextureFilter.Linear;
parameter.fontParameters.magFilter = Texture.TextureFilter.Linear;
if(withStroke) {
parameter.fontParameters.borderStraight = true;
parameter.fontParameters.borderColor = Color.BLACK;
parameter.fontParameters.borderWidth = 1.5f;
}
parameter.fontParameters.color = Assets.fontColor;
(then I load my font in static variable in Assets class)
everything is normal if the app runs for the first time,
here is the generated text with outline screenshot:
screenshot
but after I close my app using this line
Gdx.app.exit();
and then open my app again, the outline is now starting to acting weird
here is the screenshot of weird generated font:
screenshot
I'm already trying to dispose my asset manager in event dispose of ApplicationListener in Gdx, but sometime my font still acting weird.
if I clear my processing run in all task android, then the font is normal again.
Can you tell me possible solutions of why it is happening, and do you have any suggestions?
Thx
Android sometimes keeps static (final) variables even when the app lost its context.
When using static variables: make sure you dispose when required and set them to null afterwards. Or do not use static for assets.
Since this problem happen because my app not closed completely because this line :
Gdx.app.exit();
is just doing this :
Schedule an exit from the application. On android, this will cause a call to pause() and dispose() some time in the future, it will not immediately finish your application"
that's why I change my way to close my app using this line:
System.exit(0);
then my app is loading and generating new font when user open my app again.
I am experiencing a strange bug in PhoneGap on Android 4.4, for which I couldn't find any solution online. In my app, I am loading a lot of different images from a remote server, and as the user navigates back and forth, new images are loaded on each page (4 at a time, to be specific, through jQuery-generated html). After having navigated back and forth for a little while, some images will randomly not show up and instead show the typical "broken image" icon.
Now, here comes the strange part: I have been following the instructions at jQuery/JavaScript to replace broken images and done a few tests of my own. In conclusion, the naturalWidth and naturalHeight parameters report the right sizes of the images, and complete reports true for all images. Therefore, the solutions mentioned in the above SO thread don't work at all. Changing the image src doesn't help, either with or without a setTimeout (I tried adding the current timestamp as a parameter to the image path as well).
Did anyone else encounter this issue at all, or am I going crazy here? :)
EDIT: By the way, no error is ever reported. Therefore, no error handler is called when loading the image, making it useless to solve the problem with the already suggested methods (see the link above).
This is how i handle error images,
<img src="images/imageName.jpg" onError="onErrorFunc(this);" alt=" " />
function onErrorFunc(elem){
var imgUrl = "https://alternative-image";
elem.onerror = function (){
elem.src='images/noimage.jpg';
}
elem.src=imgUrl;
}
Hope it helps!