내 메뉴 활동을 어떻게 알 수 있습니까?
-
20-12-2019 - |
문제
새 프로젝트에서 나침반 예제에서 사용되는 패턴을 따르고 대부분의 논리가 작동합니다.그러나 라이브 카드가 표시되는 동안 탭하면 '클릭'노이즈를들을 수 있지만 내 메뉴 활동이 표시되지 않습니다.나는 퍼즐 조각을 놓치지 만 아직 어떤 것을 알아낼 수 없었습니다.
누를 때 클릭 외에도 logcat :
에도 표시됩니다.01-08 10:02:26.796: I/ActivityManager(196): START {flg=0x10008000 cmp=com.example.speeddisplay/.SpeedDisplayMenuActivity} from pid -1
.
그래서 그것은 내 활동을 시작해야하지만 나타나지 않는 것처럼 보입니다.다음은 관련 코드 조각이 있습니다 ... 문제가있는 곳에 확실하지는 않지만
androidmanifest.xml의 서비스 부분 :
<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의 SpeedService.java의 메소드 :
@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();
}
.
누구든지 누락 된 것을 볼 수 있습니까?
해결책
이 경우 speedDisplayMenuActivity를 선언하는 것이 좋습니다.
Android 환경에서 일반적으로 발생하는 다른 많은 다른 유형의 예외 / 충돌이 유리에서 정상적으로 처리되는 경우를 보았습니다.
사용자의 경험에 대해 확실히 좋지만 개발에 거의 힘을 얻지 못합니다.앞으로도 예외를 가능하게하기 위해 몇 가지 종류의 설정이 앞으로 나아갈 수 있기를 바랍니다.
제휴하지 않습니다 StackOverflow