开发者

App crashes in FroYo & Gingerbread

开发者 https://www.devze.com 2023-03-29 16:53 出处:网络
--The anonymous answer is my answer that I solved this issue with.-- I have been writing an app for Android, all is working well in Honeycomb, but not playing nice on my FroYo & Gingerbread devic

--The anonymous answer is my answer that I solved this issue with.--

I have been writing an app for Android, all is working well in Honeycomb, but not playing nice on my FroYo & Gingerbread devices (opposite of what you'd expect right).

Here is the code that I believe is causing the issue:

@Override
protected void onStart() {
    int versionNumber = Integer.valueOf(android.os.Build.VERSION.SDK);
    if (versionNumber == 11) {
        super.onStart();
        ActionBar actionBar = this.getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}

Here I implement the ActionBar's icon-up-to-home ability, I added the versionNumber variable as I believed the lack of an ActionBar in pre-Honyecomb devices was causing the issue when the activity was run, but it still crashes and I believe this is the issue, although I am terrible with debugging and don't understand anything I am given by logcat.

Edit: logcat - I hope I got the right section?!

08-20 17:21:41.326: WARN/ActivityManager(2707): Trying to launch com.squirculardesign.android.pixel/.About 08-20 17:21:41.346: INFO/dalvikvm(4059): Could not find method com.squirculardesign.android.pixel.About.getActionBar, referenced from method com.squirculardesign.android.pixel.About.onStart 08-20 17:21:41.346: WARN/dalvikvm(4059): VFY: unable to resolve virtual method 54: Lcom/squirculardesign/android/pixel/About;.getActionBar ()Landroid/app/ActionBar; 08-20 17:21:41.346: DEBUG/dalvikvm(4059): VFY: replacing opcode 0x6e at 0x0011 08-20 17:21:41.346: DEBUG/dalvikvm(4059): VFY: dead code 0x0014-0018 in Lcom/squirculardesign/android/pixel/About;.onStart ()V 08-20 17:2开发者_开发百科1:41.386: INFO/ALSAModule(2588): Initialized ALSA PLAYBACK device hifi 08-20 17:21:41.386: WARN/AudioFlinger(2588): write blocked for 108 msecs, 3 delayed writes, thread 0x5e758 08-20 17:21:41.406: DEBUG/dalvikvm(4059): GC_EXTERNAL_ALLOC freed 38K, 52% free 2621K/5379K, external 190K/518K, paused 36ms 08-20 17:21:41.596: INFO/AudioFlinger(2588): stop output streamType (0, 1) for 1 08-20 17:21:41.596: DEBUG/AudioHardwareYamaha(2588): AudioStreamOut::setParameters(keyValuePairs="stop_output_streamtype=1") 08-20 17:21:42.096: ERROR/yamaha::media::Parameters(2588): SalesCode = OPS 08-20 17:21:42.671: ERROR/lights(2707): write_int: path /sys/devices/virtual/misc/melfas_touchkey/brightness, value 2 08-20 17:21:42.671: WARN/PowerManagerService(2707): Timer 0x7->0x3|0x3 08-20 17:21:42.671: INFO/PowerManagerService(2707): Ulight 7->3|0 08-20 17:21:42.671: DEBUG/PowerManagerService(2707): setLightBrightness : mButtonLight : 0 08-20 17:21:43.666: INFO/ALSAModule(2588): Terminated ALSA PLAYBACK device hifi 08-20 17:21:44.086: ERROR/yamaha::media::Parameters(2588): SalesCode = OPS 08-20 17:21:51.181: WARN/ActivityManager(2707): Launch timeout has expired, giving up wake lock! 08-20 17:21:51.336: WARN/ActivityManager(2707): Activity idle timeout for HistoryRecord{40a6f0a8 com.squirculardesign.android.pixel/.About} 08-20 17:21:56.456: DEBUG/dalvikvm(2929): GC_EXPLICIT freed 672K, 53% free 3917K/8327K, external 12588K/12670K, paused 121ms 08-20 17:22:01.876: INFO/StatusBarPolicy(2834): onSignalStrengthsChanged 08-20 17:22:04.006: DEBUG/BatteryService(2707): update start 08-20 17:22:04.011: ERROR/BatteryService(2707): TMU status = 0 08-20 17:22:04.011: DEBUG/BatteryService(2707): updateBattery level:79 scale:100 status:2 health:2 present:true voltage: 4050 temperature: 270 technology: Li-ion AC powered:false USB powered:true icon:17302229


This always seems to happen, I ask the question and the problem becomes clearer in my mind after having explained it so someone not in the context could understand...

The fix I found was:

//Sets the icon to 'go home' button
@Override
protected void onStart() {
    int versionNumber = Integer.valueOf(android.os.Build.VERSION.SDK);
    if (versionNumber >= 11) {
            super.onStart();
            ActionBar actionBar = this.getActionBar();
            actionBar.setDisplayHomeAsUpEnabled(true);
    }
    else {
            super.onStart();
    }
}

This fixes the problem in both Gingerbread & FroYo, the difference is that super.onStart(); us triggered no matter what.

For those of you who are inevitably going to comment on my hackish/sticky tape fix: This particular App does not need an ActionBar always, I was just using the ActionBar items in Honeycomb as it has become the UI practice to get more actions. This is why I did not implement an Ac


Have you logged what versionNumber actually is? I guess your if statement somehow is true. So try logging what versionNumber equals.

You should really use

int versionNumber = android.os.Build.VERSION.SDK_INT


Check also this:

public boolean onOptionsItemSelected(MenuItem item) {

if(item.getItemId()==android.R.id.home){
    Intent intent = new Intent(this, YourHomeActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    return true;
}

You have to declare "item.getItemId()==android.R.id.home" and ten "give" the name of your Home Activity "YourHomeActivity.class". Now when someone press the "up" button you wll be redirected to your Home activity "YourHomeActivity.class".

0

精彩评论

暂无评论...
验证码 换一张
取 消