Domanda

Sto seguendo i modelli che vengono utilizzati nell'esempio della bussola in un nuovo progetto e ha la maggior parte del funzionamento della logica.Tuttavia, quando toccasi mentre viene visualizzata la mia scheda dal vivo, sento il rumore "Fare clic" ma la mia attività di menu non viene visualizzata.Penso che mi manca un pezzo del puzzle, ma non sono stato in grado di capire cosa ancora.

Quando tocco, oltre al clic, vedo anche questo in logcat:

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

Quindi sembra che dovrebbe iniziare la mia attività, ma non si presenta.Ecco alcuni pezzi di codice pertinente ... anche se non sono sicuro di dove si trova il problema.

Porzione di servizio in 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 Metodo in 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;

}
.

Ecco la mia speeddisplaymenuactivity.java.Nessuno di questi metodi viene chiamato.

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();
}
.

Qualcuno vede cosa mi manca?

È stato utile?

Soluzione

È giusto, dichiarare la speeddisplaymenuattività è il problema in questo caso.

Ho visto casi in cui molti altri tipi di eccezioni / crash che normalmente accade nell'ambiente Android viene gestito con grazia in vetro.

È decisamente buono per l'esperienza dell'utente, ma è poco duraturo per lo sviluppo.Speriamo che alcuni tipi di impostazioni vengano in futuro per abilitare le eccezioni pure in futuro!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top