make android application performance better - android

my android application performance is low, it takes a long startup time. i have 5 buttons, one imageview, 3 textView, 2 editText and one listView initialized in onCreate() method. Is large number of ui object the reason for slow startup?? Is there any fault in manifest.xml??
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ars.application"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/lightvasicon" android:label="#string/app_name" android:debuggable="true">
<activity android:name=".LightVas"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission
android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>
<uses-permission
android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission>
<uses-permission
android:name="android.permission.CONTROL_LOCATION_UPDATES"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk android:minSdkVersion="7" />
</manifest>

Generic performance advice:
In most cases you shouldn't try to guess what is causing performance problems as intuition is often wrong. If you knew the cause of slow code, you wouldn't have written it slow in the first place!
Use the profiler to work out where your performance problems are.
Optimize just the slow parts. Keep a copy of your traces and compare them after making a change, so you know whether you're heading in the right direction or not.
Make your own simple timing method to verify your results, this will make sure that trace recording itself is not causing performance issues in a different place.

Related

Android TV forces app in portrait mode

I have an Android mobile app and now I'm trying to run it on Android TV emulator, but it doesn't respond to screen orientation, it is always in portrait mode even though I handled it in code (it0s working both on mobile and tablet).. This is my AndroidManifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="------">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.VIBRATE" />
<permission android:name="android.permission.REBOOT" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<application
android:name="-----"
android:allowBackup="true"
android:icon="#drawable/ic_launcher_2"
android:label="#string/app_nameMain"
android:launchMode="singleTask"
android:theme="#style/AppTheme"
tools:replace="android:label">
<activity
android:name=".activities.LauncherActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:launchMode="singleTask"
android:theme="#style/App.Theme.Translucent"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.LogInActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".activities.BrowserManagerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="#style/MyHomeCustomTheme"
android:windowSoftInputMode="adjustPan" />
</application>
I also tried adding this line of code but it's not helping:
<uses-feature
android:name="android.hardware.screen.portrait"
android:required="false" />
Did you have similar experience or do you have any ideas what's the problem here?
I think it is not about your application orientation configurations. Many Android-tv producers force the orientation as landscape. If you have access, you may check system properties and find about x.forceorientation:landscape and change it.
Some producers have also put a settings menu option such as System Settings > Display > Rotate.
Another way, this application can work on some devices
I had the same problem but with a real TV device - the system ignored rotation at all (everything worked fine on tablets and phones).
I found solution for my case but it can be inappropriate for you.
So, the short answer is "impossible" the long answer goes here:
Firmware for TV devices often tweaked by their manufacturers, in my case it was /system/framework/services.jar
that contained services\com\android\server\wm\WindowManagerService.java
in which the following code handled the rotation case:
if ("box".equals(SystemProperties.get("ro.target.product", "tablet"))) {
rotation = 0;
}
of course the /system/build.prop has setting ro.target.product=box, when I tried to patch this file (I had root and possibility to reflash firmware) the system went into the kind of boot loop. The parameter ro.target.product was used several times inside system applications so I think that final firmware in my case lacks some additional code to handle other target modes. Because of this I was forced to patch classes.dex directly in order to turn this checking off.
Another set of options that controls rotation are persist.demo.hdmirotates and persist.demo.hdmirotation, by default they were turned off. When I added them via the command line:
setprop persist.demo.hdmirotates true
setprop persist.demo.hdmirotation landscape
I got desired behavior: my application chooses necessary orientation and it works! In my case the rotation of TV depends upon cabling requirements, i.e. the relative position of TV and its corresponding socket outlet on the wall.
So, no free lunch :-( each device should be handled separately.

Why is my app ranking so low in the Play Store when I type the exact name?

The app was published about a month ago, and when I do a search for the exact name of the app Turbo Verse it ranks very low 25th at the highest, currently its #92.
I understand the basic SEO rules for the play store (downloads, rankings, compatibility etc.) but I feel this is an anomaly because this is the only app in the entire store that contains the words Turbo and Verse in the title and I can see no reason why it shouldnt be ranked very high for the exact name.
I was thinking it may have something to with the manifest so I will post it below, I have 18 reviews, mostly positive and over 100 downloads.
The full name of the App as it appears in the store is: Turbo Verse KJV - Bible Memory but I am only typing in the first part: Turbo Verse, but when I type the whole name into the search its still ranking about 9 or 10th
I would really appreciate any advice, I am a new developer and I would like to learn from my mistakes.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.turboverse.scripturememory"
android:versionCode="2"
android:versionName="1.01" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:description="#string/appDescription"
>
<activity
android:name="com.turboverse.scripturememory.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".RequestVerse" android:screenOrientation="portrait" />
<activity android:name=".ByReferenceBookList" android:screenOrientation="portrait" />
<activity android:name=".ByTopicList" android:screenOrientation="portrait" />
<activity android:name=".Chapters" android:screenOrientation="portrait" />
<activity android:name=".Verses" android:screenOrientation="portrait" />
<activity android:name=".PlayVerse" android:screenOrientation="portrait" />
<activity android:name=".MyVersesList" android:screenOrientation="portrait" />
<activity android:name=".ChapterVerses" android:screenOrientation="portrait" />
<activity android:name=".UpdateDownloadVerses" android:screenOrientation="portrait" />
<service android:name=".TurboVerseService" />
</application>
<!-- application android:name="GlobalObjects" android:label="#string/app_name" /-->
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"><group gid="media_rw"></group></uses-permission>
<supports-screens android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
</manifest>
The google algorithm is very intelligent you are getting your app in 25th ranking because algorithm search for the keyword in all categories and push the apps which has searched keyword in there name, high downloads and ratings to top.
Because algorithm thinks from the user prospective it has to return all the type of apps in different categories because it doent knw what actually user is searching for.
Example:- If user is searching for a recorder which capture voice and He/She search for "Recorder" basically top apps will be Recorder keyword in there name and high downloads and rating from different categories also.(Check all the top 20 apps).
This above search (Recorder) results include apps like Voice Recorder, Call Recorder, Screen Recorder so now this makes sense because algorithm doesnt know what actually user is searching for thats why it gives the results like that.
So thats why your app is ranking low when you search for keyword which is part of your app name. (If you search for you app name fully it should come first if it contains a unique name as you mentioned it should not be common keywords "Recorder").
Hope this answer will help many people to understand App store optimization.

screen rotation not working on actual device but working in emulator

I have a weird problem. I set the screen orientation in android manifest and it works on emulater but not on the actual device. I also changed the orientation programmatically and still the problem persists. My manifest is as follows -
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.rotatedsignage"
android:versionCode="1"
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.rotatedsignage.MainActivity"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.example.rotatedsignage.BootReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
What is wrong with my code? The code I used -
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
any help is appreciated. Thanks in advance.
Check in your device under Settings section that whether your AutoRotate screen is locked or not.If it is locked then uncheck it.
Hope this helps.
First check your device settings as Siddharth Vyas suggest you, then make some changes like following in your config file.
<preference name="orientation" value="default" />
default means both landscape and portrait are enabled or else you can put portrait and landscape whatever you want in place of default. Hope this helps.
I restarted the app in my android phone and screen rotation started to work. I think, for a real device, if changes are made in app.json, then app needs to be restarted to see the changes.

Enable communication between two Android apps via custom permissions

One of my Android applications needs some features that are "dangerous" when it comes to permissions. They require some permissions such as "Internet access" which are critical in combination with private data.
This is why I want to create a separate "Add-on", i.e. a second app that provides these permission-critical features. So if users want them, they can install the add-on, but the main app will still work without those permissions.
Using a sharedUserId would obviously be the easiest solution, but adding this afterwards, when lots of users use the app already, could cause serious problems. Wouldn't this mean that the app can't access its own data any longer?
So I have to choose another approach. ContentProviders are something that I try to avoid, because they're too complex for this simple need in my opinion.
I thought custom permissions could solve the issue. Can they? I've added the following permission declaration to both the main app as well as the add-on as a child to the manifest tag in AndroidManifest.xml:
<permission
android:name="com.my.package.ADDON"
android:label="#string/permission_title"
android:description="#string/permission_description"
android:permissionGroup="android.permission-group.PERSONAL_INFO"
android:protectionLevel="signature" />
Furthermore, both manifest files have got this part now:
<uses-permission android:name="com.my.package.ADDON"></uses-permission>
The add-on app includes an IntentService that has the following attribute now:
android:permission="com.my.package.ADDON"
Shouldn't this do the job so that I can call the add-on's IntentService from my main app via this code?
Intent addonIntent = new Intent();
addonIntent.setClassName("com.my.package", "com.my.package.MyService");
startService(addonIntent);
Unfortunately, this call always fails with the following exception:
E/AndroidRuntime(16721): java.lang.SecurityException: Not allowed to start service Intent { cmp=com.mypackage.addon/.MyService } without permission com.mypackage.permission.ADDON
What did I do wrong? Thank you very much in advance!
Addition #1 - Add-on manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="com.mypackage.addon">
<uses-sdk android:minSdkVersion="8" />
<permission
android:name="com.mypackage.permission.ADDON"
android:label="#string/permission_title"
android:description="#string/permission_description"
android:permissionGroup="android.permission-group.PERSONAL_INFO"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:permission="com.mypackage.permission.ADDON"
android:exported="true">
<service
android:enabled="true"
android:name=".MyService" />
</application>
</manifest>
Addition #2 - main app manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="com.mypackage.mainapp">
<uses-sdk android:minSdkVersion="8" />
<permission
android:name="com.mypackage.permission.ADDON"
android:label="#string/permission_title"
android:description="#string/permission_description"
android:permissionGroup="android.permission-group.PERSONAL_INFO"
android:protectionLevel="signature" />
<uses-permission android:name="com.mypackage.permission.ADDON"></uses-permission>
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name" android:name="MyApp">
<activity android:name=".MainActivity" android:launchMode="singleTask" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Wouldn't this mean that the app can't access its own data any longer?
Correct.
I've added the following permission
I would dump the permission-group, as that should not be necessary.
Furthermore, both manifest files have got this part now
Only the one calling your IntentService might need that.
Shouldn't this do the job so that I can call the add-on's IntentService from my main app via this code?
Not if that IntentService is not exported. Make sure that your IntentService either has an <intent-filter> or android:exported="true". I would recommend going the <intent-filter> route, so you can declare and use a custom action string, so you get away from hard-coding package and class names in the client app.
Here is a directory with two sample projects using this basic approach, though in my case the communications are based on a secured ContentProvider rather than a secured IntentService. The concept is the same, though, and so with these minor tweaks, I would expect what you are doing to work just fine.

Hardware Accelerated Canvas

I an currently working on an intensive LiveWallpaper that draws to the canvas. I happened upon the following video: http://www.youtube.com/watch?v=v9S5EO7CLjo.
However when I tried to implement hardware acceleration, I get errors. Here is my code:
if (c != null && mStaticRects.length > 10 && c.isHardwareAccelerated())
drawSurfacePortrait(c);
if (c != null && mStaticRects.length < 20 && c.isHardwareAccelerated())
drawSurfaceLandscape(c);
When I run this, here is the corresponding error:
AndroidRuntime(382): java.lang.NoSuchMethodError: android.graphics.Canvas.isHardwareAccelerated
and finally here is my Manifest...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="stuff.of.mine"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.VIBRATE" ></uses-permission>
<uses-feature
android:name="android.software.live_wallpaper"
android:required="true" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
***android:hardwareAccelerated="true"***>
<service
android:name=".SomeWPService"
android:permission="android.permission.BIND_WALLPAPER"
***android:hardwareAccelerated="true"***>
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data
android:name="android.service.wallpaper"
android:resource="#xml/mylwp" />
</service>
</application>
Ok, I was searching around stackoverflow and stumbled upon the answer to my own question
In fact, Romain Guy, one of the guys in the video answered on the following thread:
Canvas in SurfaceView - hardware acceleration
He says:
A Canvas returned by SurfaceView.lockCanvas() cannot be hardware accelerated at the moment.
What I want to know is how you can create a live wallpaper without SurfaceView.lock and unlockCanvas?
canvas.isHardwareAcceleratedis introduced in API 11 and your minSdkVersion is 7. Try changing that to 11.
You can control hardware acceleration at the following levels:
Application
Activity
Window
View
in your code,
<service
android:name=".SomeWPService"
android:permission="android.permission.BIND_WALLPAPER"
***android:hardwareAccelerated="true"***>
service tag doesn't contain android:hardwareAccelerated !

Categories

Resources