Android Wear 2.0 Memory Leak - android

I created a blank Android Wear 2.0 stand-alone app project in Android Studio. I noticed that when I run the blank app on my watch there seems to be a memory leak (shown below). Is anyone else experiencing this issue?
The device I'm testing it on is an LG Watch Style, running Android Wear 2.0
This is a blank project, here is the code:
MainActivity.java
import android.os.Bundle;
import android.support.wearable.activity.WearableActivity;
public class MainActivity extends WearableActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mc.memorytester">
<uses-feature android:name="android.hardware.type.watch"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#android:style/Theme.DeviceDefault">
<uses-library
android:name="com.google.android.wearable"
android:required="false"/>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.DeviceDefault.Light">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.mc.memorytester"
minSdkVersion 25
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:2.0.3'
compile 'com.google.android.gms:play-services-wearable:11.0.4'
provided 'com.google.android.wearable:wearable:2.0.3'
}

This doesn't look like a memory leak. If you were in fact leaking, the total amount of used memory would keep increasing over time, and eventually cause a very sluggish experience and/or an OutOfMemoryException. What you see here are cycles of objects being created, and then garbage collected.
There are still things you can do to improve this, since frequent garbage collection might result in hiccups/lag.
My suggestion is to take a look at methods that are executed often (onDraw() and similar things) and make sure that you're not creating objects inside of them. If that doesn't help you can use the Android Profiler to dig deeper and find out what's being created (details about how you do that can be found e.g. here)

Related

Default Activity Not Found - Appearing on all of my projects which were previously working

I keep getting this message on all of my projects which were previously working as of yesterday: "Error running 'app': Default Activity not found"
Sorry, I've read similar posts with the same issue but haven't figured out a solution. It's not the Manifest files because I've compared them to the ones in other posts. I've pulled up two projects from about a week ago and those won't work now either.
Build --> Clean Project didn't work.
I've also tried this two or three times: File---->Invalidate Caches/Restart. Click on it and choose Invalidate Caches/Restart
I installed an update yesterday. I'm not sure what to do, I'd appreciate any help/feedback. I'm new to android studio, so please feel free to over simplify lol. :)
Here's the code I have in the AndroidManifest.xml through a project I made through a Udacity course. This one has the same error as the other projects:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.birthdaycard">
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Here's the Android Manifest file from a new project (comparing two toys - yes, I'm an adult who collects toys lol) same issue:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.example.newapplication">
<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:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".BarbieOne">
</activity>
<activity android:name=".BarbieTwo">
</activity>
</application>
Here's the build.gradle (Module:app) for the same project - Sorry, not sure if this was the right build gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "android.example.newapplication"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-
optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
}
Bro Let me explain first about your problem. Few months ago I faced same problem that's mean you want to run your app but build shows error like Default Activity not found. while before this problem your code was running very well.I know you tried lots of answer but in new studio may be from 3.0 this problem may be occurred.Some time studio does not read your launcher code from manifest file of app. OK now you have two choices.
Before this try to Rebuild, Invalidate and clean project one time again.
First Choice
Try to add one or two new activity and make them launcher one by one may be android studio read your launcher code in manifest file and you can run your app.
Note: It works only your luck.
Second choice
You can copy your code paste in new project.
Note: This is last option.
Hope so You have great luck.

How to resolve INSTALL_FAILED_MISSING_SHARED_LIBRARY on Android Things Project

I try to control a GPIO Port on Android App using the Android Things Project.
But when I run this app through ADB(on Android Studio), the following message is issued..
Installation failed with message
INSTALL_FAILED_MISSING_SHARED_LIBRARY. It is possible that this issue
is resolved by uninstalling an existing version of the apk if it is
present, and then re-installing.
WARNING: Uninstalling will remove the application data!
Do you want to uninstall the existing application?
How can I resolve this problem?
Android version is Android 5.1.1(API 22)
My Android App is coded according to the web site which explains the Android Things Project(https://developer.android.com/things/sdk/pio/gpio.html#managing_the_connection)
The build.gradle for app is the following.
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "kr.iges.wallpad.gpiotest"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.1.0'
provided 'com.google.android.things:androidthings:0.1-devpreview'
}
And AndroidManifest.xml is
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kr.iges.wallpad.gpiotest">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<uses-library android:name="com.google.android.things"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.IOT_LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
And JAVA Code is
package kr.iges.wallpad.gpiotest;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.google.android.things.pio.PeripheralManagerService;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "GpioTest";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PeripheralManagerService manager = new PeripheralManagerService();
List<String> portList = manager.getGpioList();
if (portList.isEmpty()) {
Log.i(TAG, "No GPIO port available on this device.");
} else {
Log.i(TAG, "List of available ports: " + portList);
}
setContentView(R.layout.activity_main);
}
}
Do you know the solution for this problem?
Thanks for your reading.
Add the things shared library entry to your app's manifest file:
This worked for me. Make sure you add uses-library within the application tag only.
...

Android launch mode issue

Although I have been searching on Stack Overflow for quite some time, did not find the answer I want so far.
1. Problem description:
I have an Android app with bunch of activities and submitted to
Google Play. After it's published, I downloaded it, whenever open the
app, it starts a new task. I need to click the hardware back button
several times to kill all the tasks. While, after that, whenever I
launch the app again, everything is fine.
Another weird thing is
that there's no problem if I directly install the app on the device
through adb command (adb install xxxx.apk)
2. What I did:
originally, in the code, I was using the "standard" launch mode for the launch activity. I encountered the problem as described above.
after I read the official document, I realized that "standard" mode will launch an instance of the activity everytime, so I changed the launch mode to be "singtop", but the problem is still there.
3. What I do not understand:
Why the app keeps creating new task if I install the app from Google Play. Why "Singtop" launch mode does not work in this case?
why I do not have the problem when install the app directly through adb command, while I get the problem when install app from Google Play. What's the difference.
4. Source code for reference:
build.gradle (Module:app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.testing.exampletesting"
minSdkVersion 17
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testing.exampletesting"
android:versionCode="10"
android:versionName="1.0.1" >
<application
android:allowBackup="true"
android:icon="#mipmap/app_logo"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity
android:name=".LaunchActivity"
android:launchMode="standard">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DummyAActivity" />
<activity android:name=".DummyBActivity" />
<activity android:name=".DummyCActivity" />
</application>
</manifest>

App works in emulator but not on phone

The app I am developing works perfectly on my emulator, but it won't work on my phone when I try to debug it. I only get the message:
Warning: debug info can be unavailable. Please close other application using ADB: Monitor, DDMS, Eclipse
Restart ADB integration and try again.
Waiting for process: com.deliciouslymad.tsukasa.critterbytes
It hangs there forever with no change on my phone. It doesn't work after restarting or cleaning the project, either. I've tried many solutions on this site already, but none of them have resolved this issue.
-UPDATE-
ADB logs:
ddms: null
java.lang.NullPointerException
at com.android.ddmlib.Client.sendAndConsume(Client.java:673)
at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:195)
at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:66)
at com.android.ddmlib.Client.getJdwpPacket(Client.java:772)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)
The .apk installs on my phone just fine.
I have 'USB debugging', 'allow mock locations', and 'verify apps over USB' turned on in my phone settings. Runtime is Dalvik and it's connected as a media device.
My phone runs Android 4.4.4.
If it helps, I am implementing the Zxing library into my code for barcode scanning.
Here's my AndroidManifest.xml code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.deliciouslymad.tsukasa.critterbytes">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity android:name="ScannerActivity"
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>
Here's my build.gradle code:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.deliciouslymad.tsukasa.critterbytes"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.1.0'
}
Additionally, in my app's project structure, the 'Compile Sdk Version' is API 21 and the 'Build Tools Version' is 21.1.2. 'Source Compatibility' and 'Target Compatibility' are blank, and I'm not sure if anything is supposed to be there.
The gradle builds fine with no errors, but there is something strange; when I hover over 'getDefaultProguardFile' in the build.gradle file, it says that it cannot resolve the symbol.
I am a junior programmer and trying to learn, so please let me know if there's anything missing or anything I can improve! This is all a little overwhelming and I can't figure out why it's not working.

Android: Cannot resolve symbol ActionBarActivity

I'm getting the error "Cannot resolve the symbol ActionBarActivity" when I try to import it (import android.support.v7.app.ActionBarActivity;).
I've already read some questions ActionBarActivity cannot resolve a symbol and Import Google Play Services library in Android Studio about it and i've tried the solution described there but I couldn't fix my problem.
I tried to change the targetSdK to one lower and then I wrote back that that I had before but it didn't resolve.
I'm using Android Studio version 1.0.2.
My build.grad file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.android.asminhasdespesas"
minSdkVersion 13
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
My Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.asminhasdespesas" >
<uses-sdk android:minSdkVersion="13" android:targetSdkVersion="21"></uses-sdk>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
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>
Do you have any possible resolution to fix this issue since I think this shouldn't happen with this Android Studio version. Thanks.
Looks like you're missing this import in the activity:
import android.support.v7.app.ActionBarActivity;
You can fix this by using ctrl + alt + o. A project rebuild might also do the trick.
I tried to refresh Gradle and it seemed to work! Maybe some instant problem with android studio and gradle synchronization!

Categories

Resources