2014-01-08 31 views
1

我在一个新项目中遵循Compass示例中使用的模式,并且大部分逻辑工作正常。但是,当我点击显示活卡时,会听到'咔嗒'声,但我的菜单活动不显示。我认为我错过了一个难题,但我还没有弄清楚到底是什么。如何让我的MenuActivity显示出来?

当我点击,除了点击,我也看到这一点的logcat:

01-08 10:02:26.796: I/ActivityManager(196): START {flg=0x10008000 cmp=com.example.speeddisplay/.SpeedDisplayMenuActivity} from pid -1 

所以它看起来像它应该开始我的活动,但它并没有显示出来。以下是一些相关的代码......虽然我不确定问题出在哪里。在SpeedService.java

<service 
     android:name="com.example.speeddisplay.service.SpeedService" 
     android:enabled="true" 
     android:icon="@drawable/ic_drive_50" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="com.google.android.glass.action.VOICE_TRIGGER" /> 
     </intent-filter> 

     <meta-data 
      android:name="com.google.android.glass.VoiceTrigger" 
      android:resource="@xml/voiceinput_speeddisplay" /> 
    </service> 

onStartCommand方法:在AndroidManifest.xml

服务部

@Override 
public int onStartCommand(Intent intent, int flags, int startId) { 
    if (Constants.DEBUG) { 
     Log.d(TAG, "onStartCommand"); 
    } 
    if (liveCard == null) { 
     liveCard = timelineManager.createLiveCard(LIVE_CARD_ID); 
     speedRenderer = new SpeedRenderer(this, speedManager); 
     liveCard.setDirectRenderingEnabled(true); 
     liveCard.getSurfaceHolder().addCallback(speedRenderer); 

     // Display the options menu when the live card is tapped. 
     Intent menuIntent = new Intent(this, SpeedDisplayMenuActivity.class); 
     menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 
     liveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0)); 
     liveCard.publish(PublishMode.REVEAL); 

     if(Constants.DEBUG){ 
      Log.d(TAG, "liveCard published"); 
     } 
    } 

    return START_STICKY; 

} 

这是我的SpeedDisplayMenuActivity.java。这些方法都没有被调用。

public class SpeedDisplayMenuActivity extends Activity { 

private SpeedService.SpeedBinder speedService; 
private boolean mResumed; 

private ServiceConnection mConnection = new ServiceConnection() { 
    @Override 
    public void onServiceConnected(ComponentName name, IBinder service) { 
     if (Constants.DEBUG) { 
      Log.e("Service Stuff", "Service connected."); 
     } 
     if (service instanceof SpeedService.SpeedBinder) { 
      speedService = (SpeedService.SpeedBinder) service; 
      openOptionsMenu(); 
     } 
     if (Constants.DEBUG) { 
      Log.e("Service Stuff", "service was an instance of " + service.getClass().getName()); 
     } 
    } 

    @Override 
    public void onServiceDisconnected(ComponentName name) { 
     // Do nothing. 
    } 
}; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    if(Constants.DEBUG){ 
     Log.e("Menu", "Created."); 
    } 
    super.onCreate(savedInstanceState); 
    bindService(new Intent(this, SpeedService.class), mConnection, 0); 
} 

@Override 
protected void onResume() { 
    if(Constants.DEBUG){ 
     Log.e("Menu", "Resumed."); 
    } 
    super.onResume(); 
    mResumed = true; 
    openOptionsMenu(); 
} 

@Override 
protected void onPause() { 
    if(Constants.DEBUG){ 
     Log.e("Menu", "Paused."); 
    } 
    super.onPause(); 
    mResumed = false; 
} 

@Override 
public void openOptionsMenu() { 
    if (Constants.DEBUG) { 
     Log.e("Options Menu", "Open"); 
    } 
    if (mResumed && speedService != null) { 
     if (Constants.DEBUG) { 
      Log.e("Options Menu", "Open with correct params"); 
     } 
     super.openOptionsMenu(); 
    } else { 
     if (Constants.DEBUG) { 
      Log.e("Options Menu", "Open with INCORRECT params"); 
     } 
    } 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    if (Constants.DEBUG) { 
     Log.e("Options Menu", "Created"); 
    } 
    getMenuInflater().inflate(R.menu.speed, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    if (Constants.DEBUG) { 
     Log.e("Options Menu", "Item Selected"); 
    } 
    switch (item.getItemId()) { 
    // case R.id.read_aloud: 
    // mCompassService.readHeadingAloud(); 
    // return true; 
    case R.id.stop: 
     if (Constants.DEBUG) { 
      Log.e("Options Menu", "Stop"); 
     } 
     stopService(new Intent(this, SpeedService.class)); 
     return true; 
    default: 
     return super.onOptionsItemSelected(item); 
    } 
} 

@Override 
public void onOptionsMenuClosed(Menu menu) { 
    if (Constants.DEBUG) { 
     Log.e("Options Menu", "Closed"); 
    } 
    super.onOptionsMenuClosed(menu); 

    unbindService(mConnection); 

    // We must call finish() from this method to ensure that the activity 
    // ends either when an 
    // item is selected from the menu or when the menu is dismissed by 
    // swiping down. 
    finish(); 
} 

有人看到我失踪了吗?

+1

您是否已在您的Manifest中注册了SpeedDisplayMenuActivity? – KickAss

+0

我看不到SpeedDisplayMenuActivity.java它在您的清单文件中定义的任何地方。你检查了吗? –

+0

你们都很棒。我总是忘记在我的Manifest中添加新的活动....我只是习惯于“正常”的Android应用程序崩溃,这就是我的记忆:)看起来玻璃器皿正好失败。 – Innova

回答

1

这是正确的,在这种情况下声明SpeedDisplayMenuActivity是问题。

我见过在Android环境中正常发生的很多其他类型的异常/崩溃的情况在Glass中得到了优雅地处理。

这对用户体验绝对有好处,但对开发没什么困难。希望将来有些设置会在将来启用例外情况!

+0

是的,我喜欢这个问题的优雅处理,但日志中的消息会有帮助!我相信他们仍然在研究这样的细节。 – Innova

+0

希望如此。否则这将很难理解正在发生的事情。 – sivag1