Android Custom Launcher doesn't stop the BootAnimation - android

I am working on a custom launcher for Android, in a project using BBBAndroid (android v4.4.4 w/ kernel 3.8 for the beagleboneblack):
http://bbbandroid.sourceforge.net
I created aosp_stripped.mk to strip some unneeded Android packages and replace the Launcher2 and the HOME packages with my CustomLauncher. This launcher is mostly an normal app with the LAUNCHER and HOME category added in its AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.customlauncher" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_people"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library
android:name="test.service.lib"
android:required="true" />
<activity
android:launchMode="singleTask"
android:stateNotNeeded="true"
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
It effectively replaces Launcher2, but the boot animation doesn't stop until 40 seconds later, logcat shows:
W/WindowManager( 591): ***** BOOT TIMEOUT: forcing display enabled
I/PowerManagerService( 591): Boot animation finished.
So my launcher must be missing something to tell the boot animation to stop. I found some hints here: http://forum.xda-developers.com/showthread.php?t=2485118
Indeed, I have some missing Wallpaper classes errors in logcat, but I didn't remove the SystemUI package. I noticed that when using Launcher2/Home, this error only happens on the first boot. Using my custom launcher, it happens on every boot. Besides this error, I didn't find any differences:
W/WallpaperService( 591): Attempted wallpaper ComponentInfo{com.android.wallpaper/com.android.wallpaper.fall.FallWallpaper} is unavailable
W/WallpaperService( 591): Failure starting previous wallpaper
W/WallpaperService( 591): Attempted wallpaper ComponentInfo{com.android.wallpaper/com.android.wallpaper.fall.FallWallpaper} is unavailable
E/WallpaperService( 591): Default wallpaper component not found!
I found this class in the package LiveWallpapers in packages/wallpapers/Basic (AOSP). It is already added in PRODUCT_PACKAGES, but this package is nowhere in out/target/product/beagleboneblack/ :(
Right now I am digging in Launcher2 and WallPaperManager to see what could trigger the BootAnimation to stop...
Thanks in advance !
Update
I also tried to stop the bootanimation using system properties, but the touchscreen is not usable until the BOOT_TIMEOUT event:
import android.os.SystemProperties;
// inside a Service with system privileges
SystemProperties.set("service.bootanim.exit", "1");

Tracing the BOOT TIMEOUT problem, it comes from WindowManagerService performEnableScreen() waiting for a wallpaper to be set/active, the boot isn't considered done otherwise:
// If we are turning on the screen after the boot is completed
// normally, don't do so until we have the application and
// wallpaper.
if (mSystemBooted && ((!haveApp && !haveKeyguard) ||
(wallpaperEnabled && !haveWallpaper))) {
return;
}
I also noticed that the wallpapers apks in packages/wallpapers are not built for the target because the bbbandroid repo lacks opengl support for now.
My current workaround for this problem is to disable the WallpaperService via its internal config.xml file:
diff --git a/frameworks/base/core/res/res/values/config.xml b/frameworks/base/core/res/res/values/config.xml
index 6efb4a4..0c873b7 100644
--- a/frameworks/base/core/res/res/values/config.xml
+++ b/frameworks/base/core/res/res/values/config.xml
## -701,7 +701,7 ##
<string name="default_wallpaper_component" translatable="false">#null</string>
<!-- True if WallpaperService is enabled -->
- <bool name="config_enableWallpaperService">true</bool>
+ <bool name="config_enableWallpaperService">false</bool>
<!-- Whether to enable network location overlay which allows network
location provider to be replaced by an app at run-time. When disabled,
This solution works if you don't mind using modified android sources.

I think that the problem is not with your launcher app, in this case you would see in logcat errors from your app. Usually boot animation hangs when SystemUI can't start (due to a failure).
Launcher app itself doesn't stop boot animation, it doesn't have this functionality.
You probably disabled some critical component which breaks boot workflow. Yes, wallpapers can affect it. I would recommend to put everything back in your .mk file, check that it builds and boots OK, then replace launcher only with your app. Then you can cut mk file further to check which module creates the issue.
I do not remember exactly but Browser module may include webview component which is used by many components.
You should post full logcat output, and may be dmesg output as well.

Related

I can't get the Cast Companion Library notification to work

I am using the Cast Companion Library and it is mostly working fine, I get the mini player, and also the lock screen controls and the activity for playing content, but I can never get the notification screen to show. I am doing the following when initializing:
mCastMgr.enableFeatures(VideoCastManager.FEATURE_NOTIFICATION |
VideoCastManager.FEATURE_LOCKSCREEN |
VideoCastManager.FEATURE_DEBUGGING);
and I am doing the incrementUiCounter() on resume and decrementUiCounter() on pause.
I don't see any errors, I just don't see what I am doing wrong. The only thing I am missing is that I am not passing URLs for images when telling media to play because my URLs are local assets to my app and I'm just not sure how to pass those.
Are you using that with your own app or with CastVideos-android? If your own app, first I suggest you try the CastVideos-android app to make sure that works for you.
I suggest you print out the value of mVisibilityCounter in BaseCastManager.incrementUiCounter() and decrementUiCounter() to see if as you move in and out of different activities, it reflects the correct counter. When that counter reaches zero, then notification should show up. If the counter is reaching zero and the notification doesn't show up, I suggest you check your manifest file and see if you have the following in your Manifest:
<service
android:name="com.google.sample.castcompanionlibrary.notification.VideoCastNotificationService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.sample.castcompanionlibrary.action.toggleplayback" />
<action android:name="com.google.sample.castcompanionlibrary.action.stop" />
<action android:name="com.google.sample.castcompanionlibrary.action.notificationvisibility" />
</intent-filter>
</service>
(you can copy-and-paste from the CastVideos-android manifest file). You may have grabbed what it is from the documentation; there is an error there (I am planning to update a bunch of things tonight or tomorrow and the documentation will be updated as well); basically when the counter reaches zero, it calls into the notification service (see the onUiVisibilityChanged() in VideoCastManager) and if that action in manifest is not correctly set, the notification never gets our memo! Let me know if that is not the issue.
I had the same trouble. Just an FYI to those looking at this in 2016. The manifest entry is now different. I suggest to grab whatever is in the manifest of the CastVideos-android project.
<receiver android:name="com.google.android.libraries.cast.companionlibrary.remotecontrol.VideoIntentReceiver" />
<service
android:name="com.google.android.libraries.cast.companionlibrary.notification.VideoCastNotificationService" />
<service android:name="com.google.android.libraries.cast.companionlibrary.cast.reconnection.ReconnectionService"/>

App completely restarting when launched by icon press in launcher

I'm in the process of trying to make a release build of my first android app to send to a few testers. However, I ran into a problem with it. When you exit the app and then re-enter it by launching it via its icon, it restarts the whole app instead of returning to it's previous location. This occurs even if you re-enter right after exiting. However, it does not happen if I hold the Home button and launch it through the recent apps list.
I've searched online for others having this problem and there are a few, but no one has ever had a solid answer as to why it's happening to them. It's been suggested in old questions to set the launchmode to singletask or singleinstance in the manifest file, but that hasn't helped me, and besides - from what I understand, the default behavior for android is to return to the previous state of the task in this situation, so I don't know why I would need special manifest options to make it do that.
The most bizarre thing about this problem is that if I use eclipse and the debugger to put the app on my phone, this problem does not occur. I don't even need to be connected to the debugger, it seems like as long as I have a debug version of the app, the problem doesn't occur. But if I use a release version (I create it using the Android Tools - Export Signed Application Package menu option in Eclipse), the problem happens.
If anyone has any insight as to what is causing this, I'd love to hear your thoughts.
I had the same problem with an application and I resolved this behavior adding flag "android:launchMode="singleTop"" instead of "android:launchMode="singleTask"" in the <activity> declaration of your AndroidManifest.xml file. Hope this will help somebody.
So far I've found out that it's an issue based on how you install it in your real device, specifically:
If you simply copy and paste the APK to your device's local storage and install it from the device, regardless of whether it's signed or unsigned or taken from bin folder, it shows this behavior, app restarts from menu icon.
If you install it using one of the following options, This issue does not appear:
Go to sdk/tools/ using a terminal or command prompt then type
adb install <FILE PATH OF .APK FILE>
In Linux, type:
./adb install <FILE PATH OF .APK FILE>
Simply run your project from Eclipse.
I would be pleased to know if there's any possible way to distribute correct APKs for beta testing. I already tried exporting a signed APK because when you copy and paste an APK and install it manually it shows the rogue behavior.
Update:
I found out a solution. Follow these two Steps:
Set android:launchMode="singleTask" = true for all activities of your app in the AndroidMainifest.xml inside the activity tag.
Put this code in your Launcher Activity's onCreate().
if (!isTaskRoot())
{
final Intent intent = getIntent();
final String intentAction = intent.getAction();
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) {
finish();
return;
}
}
This behavior is a bug in Android. Not a special case.
// To prevent launching another instance of app on clicking app icon
if (!isTaskRoot()
&& getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
&& getIntent().getAction() != null
&& getIntent().getAction().equals(Intent.ACTION_MAIN)) {
finish();
return;
}
write the above code in your launcher activity before calling setContentView. This will solve the problem
You could use launchMode as singleTop to the Launcher Activity in AndroidManifest.xml
<activity
android:name="<YOUR_ACTIVITY>"
android:label="#string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It is the default behavior in Android. For the debug builds it works differently for some reason. It can be solved by adding android:launchMode="singleInstance" to the activity, you want to restart after you launch from the icon.
Add this to your first activity:
if (!isTaskRoot()) {
finish();
return;
}
super.onCreate(savedInstanceState);
Try using android:alwaysRetainTaskState as shown in the following example:
<activity
android:name="com.jsnider.timelineplanner.MainActivity"
android:alwaysRetainTaskState="true"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
For me, I found that I had erroneously posted NoHistory = true in my activity attribute
[Activity(NoHistory = true, ScreenOrientation = ScreenOrientation.Landscape)]
This prevented the app resuming into this activity and restarted
You can try to set android:alwaysRetainTaskState="true" for your launcher activity in AndroidManifest.xml.
<activity
android:name=".YourMainActivity"
android:alwaysRetainTaskState="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
For details you can see https://developer.android.com/guide/topics/manifest/activity-element.html#always
I see this issue on Android TV in 2019. Is there a better fix for it? other than
if (!isTaskRoot()) {
finish();
}
It works but looks like a hack more than the actual solution.
All of the solutions above didn't work consistently on all of my devices. It worked on some Samsung but not all.
The cause of the problem for me was installing the APK manually.
For me the fix was adding LaunchMode = LaunchMode.SingleTop to my Activity attribute over the Main Activity:
/// <summary>
/// The main activity of the application.
/// </summary>
[Activity(Label = "SilhuettePhone",
Icon = "#drawable/icon",
Theme = "#style/MainTheme",
MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
ScreenOrientation = ScreenOrientation.Portrait,
LaunchMode = LaunchMode.SingleTop,
WindowSoftInputMode = SoftInput.AdjustResize)]
I had a problem with a restarting app, my problem was in themes:
I have differents fragments and I would have one background for all. But this cause a restarting app in some devices(.
I've deleted this line in themes and this helped:
item name ="android:windowBackground">#drawable/background /item
Removing task affinity rather than launch mode has worked somewhat for as it has its own demerits
When you press the back button in Android, the onDestroy method is invoked (as opposed to pressing the home button, where only the onPause() method is invoked).
If you need your app to continue where it left off, save the state of the app in your onDestroy() method and load that state in the onCreate() method.

Exception when I run my application from Eclipse

I've been having this problem for almost 2 months now and can't figure it out. The problem is that if my application is running and I run (reinstall) my application from Eclipse, I get an error message indicating that my application has crashed 'Unfortunately, has stopped.'. I notice that it also occurs when I run it away from my PC/Eclipse, I think that it happens only after I don't run it for a while.
It only occurs if the app is active in the 3rd activity (BaseDiagramActivity) and then I run the app again from Eclipse. I've stripped out basically all the application except the 3 activities and It's still happening.
I've searched and searched for a solution to this problem but can't find any good answer or one that applies to me.
It doesn't seem like a hardware or android version issue as I'm running this on my tablet (4.0.3) and my phone (4.0.2, was happening on 4.0.1 before update). Unless of course it is an ice cream sandwich bug.
Let me know if any more info is required.
The exception (Tag=AndroidRuntime)
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3938)
at android.app.ActivityThread.access$1300(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:362)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:305)
at android.app.LoadedApk.makeApplication(LoadedApk.java:474)
... 11 more
The Android Code
LoadedApk.initializeJavaContextClassLoader() - Line 362 seems to be the offender
Below are the relevant files:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="[my package]"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="HomeActivity"
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="LoadDiagramActivity" android:label="Load Diagram"></activity>
<activity android:name="BaseDiagramActivity" android:label="Base Diagram"></activity>
</application>
</manifest>
HomeActivity.java
public class HomeActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
Button diagramButton = (Button)findViewById(R.id.diagram);
diagramButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(HomeActivity.this, LoadDiagramActivity.class));
}
});
}
}
LoadDiagramActivity.java
public class LoadDiagramActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.load_diagram_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.add_new_diagram:
startActivity(new Intent(this, BaseDiagramActivity.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
BaseDiagramActivity.java
it doesn't actually matter what activity this is, the exception occurs as long as a 'third' activity is started (or clicking the add button on LoadDiagramActivity.
public class BaseDiagramActivity extends Activity {
}
home.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/diagram"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Diagram" />
</LinearLayout>
Additional information
When I stripped down my project in order to ask a simpler answer, I moved everything into the package's namespace. In the actual project there are 5 namespaces, they were still present when I was testing with the stripped down version however just not called (as far as I could see).
Here are the packages:
[package] - general logic
[package].activities - all activities and base activities
[package].database - all interaction with the database
[package].models - models for saving/loading data
[package].renderables - objects drawn to a canvas
I have tried to add an `android:sharedUserId' attribute to the manifest and and it seemed to do nothing both times I tried. When I was initially investigating this I came to the conclusion that the shared user id only applied to different projects, not different packages.
Also I don't believe there was any interaction with the database when I stripped everything down. The fact that the 3rd activity could be any activity, even HomeActivity, was something against this theory.
Useful links
stackoverflow: android.app.Application cannot be instantiated due to NullPointerException
GreoCode android.app.LoadedApk on 4.0.1
Possible race condition?
Android issue #25869
Update 1/11/2012
Last couple of days I've jumped back into this project, I created a brand new project in Eclipse Juno (was on Helios before) and transferred everything over manually so that Eclipse and Android tools handled almost all of the Manifest interaction but it's still occurring. I will look at it a bit more over the next few days and update if I find anything.
FYI my new project is targeting the following:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="15" />
The new project structure also has all the activities in the root package now (ie. [package], not [package].activities). I'm also using the (new?) syntax to show the parent activity:
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="[my package].LoadDiagramActivity" />
It is also still occurring on my now updated Galaxy Nexus running Jellybean 4.1.2.
Try adding one more thing in Manifest file, I am sure you have already tried..
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="[my package]"
android:versionCode="1"
android:versionName="1.0"
android:sharedUserId="com.mj.app" >
It seems like in your project you have multiple PACKAGES, like com.package.p1 , com.package.p2 ,com.package.p3..
And while starting you are in p1 and then moves on to p2 - p3...
and at that time you try to run it again..so the Android gives you error.
If you put 13 in your minSdkVersion, it should work.
Either that, or you need to setDisplayHomeAsUpEnabled(false) in the onCreate() of your other activities.
Both those solutions should work.
Starting at API Level 14 according to the documentation, the setHomeButtonEnabled(true) is no longer done for you by default, and it goes on to say that
Setting the DISPLAY_HOME_AS_UP display option will automatically enable the home button.
So we can infer that setDisplayHomeAsUpEnabled(false) works in a similar way as setHomeButtonEnabled(false)
If I am not mistaken, this only happens when we reinstall the app from Eclipse Run->As. So this is unlikely to happen when a user upgrades through Play. I can say this with confidence since I did notice my app too with this exception during reinstall through Eclipse, but nothing on Crittercism.
To fix this, I worked on resolving memory consumption of my app.
If you only have 1 set of drawables, then change that. Create a drawables-mdpi and copy all the file from that 1 drawables folder (drawables, drawable-ldpi). If you have just 1 set, Android will resize it for its use on bigger screens, thus internally taking up too much memory, and cleanup of this kind of memory (bitmap) is bug prone. Sound crazy, but does wonders. Dont believe me, run it under Heap memory usage watch before and after this change, you will notice that your app is taking 25% less memory for a common scenario.
If you are doing any Bitmap operations, you may want to consider downscaling. Atleast when you are setting options you definitely want to downscale it. Check here and here. Search or downscaleing.
Finally dont forget to bitmap.recycle(); bitmap = null; in your onDestroy and before all System.exit(0).
Android does a lot of background work, and reinstallation is a abrupt cleanup expectation from the app. Memory not cleaned up can cause issues. This exception is one of those internal ones. So dont think of it to be straightforward.
You haven't added the period to the names of your activities in manifest's android:name attributes. Perhaps, this causes the problem.
Wait after your application crashes when u run it second time. The app will launch after the crashing again. This happens sometimes with me. If the same is the case with u dont forget to clean your project everytime before u run it.
By inspecting your code I feel you are skipping to set "setContentView(rid)" in LoadDiagramActivity. Please try setting the view in onCreate().
Hope this will help you.
You need to append "." before the activity name in Menifest.
Like this
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk android:minSdkVersion="14" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".HomeActivity"
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=".LoadDiagramActivity" android:label="Load Diagram"></activity>
<activity android:name=".BaseDiagramActivity" android:label="Base Diagram"></activity>
</application>
I update your menifest's activity. Please check it...
There is nothing wrong with the code you've given us so far. I just tried it in a new project with the package name com.test and it worked flawlessly. The only thing I added in the files were the package declaration. (And I added the load_diagram_menu.xml, of course.)
If possible, it would be great if you could give us access to the complete project. If the project is working on someone else's computer, it's most likely Eclipse or the Android Eclipse plugin-in that are misbehaving. A clean install of Eclipse would solve that. (Though I understand how being offline could make this difficult. :-) )
For this, be sure to have the "Build Automatically" checked when cleaning the project. (Project -> Build Automatically)

Changing launcher Activity name in a new application version

I have developed a new release of an application and I have changed the name of the activity which is launched.
Before the upgrade, in the manifest was:
<activity
android:name=".Splash"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and then I only changed the name and the package of the activity and now it is:
<activity
android:name=".view.SplashActivity"
... >
...
</activity>
what happens is that after people download the application from the market, the launcher is not refreshing and it still calls to the old path to the activity.
Do you know how to solve this?
Refer Things That Cannot Change
It says,
A subtle but important aspect of what constitutes a break in compatibility is the android:name attribute of your activity, service, and receiver components. This can be surprising because we think of android:name as pointing to the private code implementing our application, but it is also (in combination with the manifest package name) the official unique public name for that component, as represented by the ComponentName class.
Changing the component name inside of an application can have negative consequences for your users. Some examples are:
If the name of a main activity of your application is changed, any shortcuts the user made to it will no longer work. A shortcut is an Intent that directly specifies the ComponentName it should run.
If the name of a service implementing a Live Wallpaper changes, then a user who has enabled your Live Wallpaper will have their wallpaper revert to the system default when getting the new version of your app. The same is true for Input Methods, Accessibility Services, Honeycomb’s new advanced Widgets, and so on.
If the name of a receiver implementing a Device Admin changes, then as with the live wallpaper example, the device admin will be disabled when the application is updated. This also applies to other kinds of receivers, such as App Widgets.
So if possible, don't change the name of components declared in the manifest, or remove any icon pointing to that component using below code.
ComponentName componentToDisable = new ComponentName("application.package.name", "packagename.ActivityClassName");
getPackageManager().setComponentEnabledSetting(componentToDisable, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Also specify new launcher activity in manifest using <intent-filter>...</intent-filter> so that your new activity will be launched when user clicks launcher icon.
Does the activity is called correctly if you start the activity in debug mode on your phone.
If so check if you did something of the following:
you changed the whole package name
you signed it not at all or not correctly
Also you might check out http://developer.android.com/guide/publishing/publishing_overview.html
Anyway. If the application runs correctly on your debugging phone there is something wrong with your publishing parameters and you should go through the page above step by step.
If not you might check the path values, like package and name of the activity and the filters.

Can't debug through onReceive() in boot completed receiver

Thanks a ton to this site, I have made significant progress with my first Android project.
I'm trying to get the execution suspend in the onReceive() method of a boot completed receiver. Below are my manifest and receiver code.
Android 2.3.3
API - 10
IDE - Eclipse
Running on emulator
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.demo.notepad3" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:icon="#drawable/icon" >
<activity
android:label="#string/app_name"
android:name=".ProjectTrackerHomeActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ProjectTrackerEditActivity" />
<receiver android:name=".ProjectTrackerNotification" />
<receiver
android:name=".ProjectTrackerOnBootReceiver" >
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
Receiver:
public class ProjectTrackerOnBootReceiver extends BroadcastReceiver {
private ProjectTrackerDBAdapter mDbHelper;
#Override
public void onReceive(Context context, Intent intent) {
Debug.waitForDebugger();
AlarmManager
mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
//I place the break point at line 2, the alarm manager line
// Further code, irrelevant
}
My observations -1. When I run this application in debug mode on eclipse, the break point is not even hit.2. When I run some other application in debug mode, this break point is hit momentarily! But before I can proceed with a step by step execution, the execution resumes. It doesn't stop there.
My reasoning for this behavior is that -1. When I run some other application, since this above app is already installed, it catches the boot complete broadcast and so the breakpoint is hit. (But why doesn't the execution halt at the breakpoint?)2. When I run only this app, it gets installed first and in the time it takes for installation, it misses the boot complete broadcast.
May I please get some assistance with the below queries -1. How can I make the execution halt at the breakpoint without it resuming further?2. Can I somehow run an already installed version of this app on the emulator in debug mode "without having it to get freshly installed" on the emulator every time I run it?
3. Is there anything else I'm doing wrong or missing something?
Kindly let me know since I really need to debug through onReceive() to catch further application logic bugs. Thanks a lot, folks.
You need to shutdown the phone and start it up to ever see onReceive get called from bootcompleted. To debug this, just add a Log statement in onReceive instead of setting a breakpoint. Otherwise, you'll have to add some action to the receiver in the manifest and then manually sendBroadcast(new Intent("someName")) with the name you specified in the receiver element in the manifest.
Not sure why this question is asked so many times and it was so hard to find the answer but this works like a champ for me.
In your receiver class within the onReceive() override add the below call for waitForDebugger() as the first call.
Deploy to the device by running the app.
Once the updated apk is on the device, reboot the device.
While device is rebooting return to your IDE (In this example Android Studio 1.4) and go to "Run" menu > "Attach debugger to Android Process".
Check "Show all processes".
Wait... Once the waitForDebugger() line is hit, your app/package will appear in this list. In my case, it took at least 2 minutes AFTER the device rebooted.
Click "OK", wait a moment and your breakpoint will be hit.
You can now step through your code like normal. Have fun!
#Override
public void onReceive(Context context, Intent intent) {
// Add this at beginning of method
android.os.Debug.waitForDebugger();
// Place breakpoint below
String myVariable = "Some Value";
}
Another method which I prefer as it means you do not need to keep restarting the device(boring, gradle takes long enough to load as it is), is to simply run the app in debug mode and then simulate an action which will call your Broadcast receiver using the following command in your terminal.
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -p com.example.package_name
The above creates a broadcast with action "BOOT_COMPLETE" and now you can debug without restarting.
Use the below line before the code where you want the debugger to stop:
android.os.Debug.waitForDebugger();

Categories

Resources