I am trying to convert an activity to a fragment and have problems with getFragmentManager.
my xml file:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map"
tools:context="xpak.probandosidebar.MapsFragment"
class ="com.google.android.gms.maps.SupportMapFragment" />
and my java file:
public class MapsFragment extends Fragment {
private GoogleMap mMap;
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
return inflater.inflate(R.layout.fragment_maps,container,false);
}
#Override
public void onStart() {
super.onStart();
setUpMapIfNeeded();
}
#Override
public void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
if (mMap == null) {
//here is the error
mMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}}
the error is: cannot cast android.app.Fragment to com.google.android.gms.maps.SupportMapFragment
I searched everywhere without success , I hope you can help me
greetings from chile
Try doing this
<com.google.android.gms.maps.SupportMapFragment
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map"
tools:context="xpak.probandosidebar.MapsFragment"
class ="com.google.android.gms.maps.SupportMapFragment" />
Related
I have an ObservableCollection<List<Model>> Data in my ViewModel.
In my Page I need a CarouselView, in which each ItemTemplate shows the data of the Data list in a ListView.
Currently, I am doing that in that way:
<CarouselView ItemsSource="{Binding Data}">
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout>
...
<ListView ItemsSource="{Binding .}">
...
</ListView>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
In the way I am doing that I get a "Specified cast not valid" exception, in which I see the following additional information:
{System.InvalidCastException: Specified cast is not valid.
at (wrapper castclass) System.Object.__castclass_with_cache(object,intptr,intptr)
at Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].ActivateContent (System.Int32 index, System.Object item) [0x00032]
in <62e3629c74b84e3d834046331d2bb5f8>:0
at Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].CreateContent (System.Int32 index, System.Object item, System.Boolean insert) [0x00000]
in <62e3629c74b84e3d834046331d2bb5f8>:0
at Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].GetOrCreateContent (System.Int32 index, System.Object item) [0x00023]
in <62e3629c74b84e3d834046331d2bb5f8>:0
at Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].get_Item (System.Int32 index) [0x0000e]
in <62e3629c74b84e3d834046331d2bb5f8>:0
at Xamarin.Forms.Platform.iOS.ListViewRenderer+ListViewDataSource.GetCellForPath (Foundation.NSIndexPath indexPath) [0x00007]
in D:\a\_work\1\s\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:1397
at Xamarin.Forms.Platform.iOS.ListViewRenderer+ListViewDataSource.GetCell (UIKit.UITableView tableView, Foundation.NSIndexPath indexPath) [0x00021]
in D:\a\_work\1\s\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:1105
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.Type principalClass, System.Type delegateClass) [0x0003b]
in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:85
at App.iOS.Application.Main (System.String[] args) [0x00001]
in <Path>\Main.cs:18 }
The Model holds only string values, so the exception cannot come from this.
I'm not sure why you're getting that specific exception. I couldn't get the ListView inside of a CarouselView to work either.
However, it works when you use a bindable StackLayout instead of a ListView. My guess is that the bindable StackLayout doesn't support scrolling and thus doesn't fight with the CarouselView but I don't know.
MainPage, MainViewModel and items
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Xamarin.Forms;
namespace App1
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
}
public class MainViewModel
{
public ObservableCollection<Item> Data { get; }
public MainViewModel()
{
Data = new ObservableCollection<Item>(GenerateItems());
}
private IEnumerable<Item> GenerateItems()
{
return Enumerable.Range(1, 10)
.Select(a => new Item
{
ItemTitle = $"Item {a}",
SubItems = Enumerable.Range(1, 10).Select(b => new SubItem { SubItemTitle = $"SubItem {b}" }).ToList()
});
}
}
public class Item
{
public string ItemTitle { get; set; }
public List<SubItem> SubItems { get; set; }
}
public class SubItem
{
public string SubItemTitle { get; set; }
}
}
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="App1.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App1">
<ContentPage.BindingContext>
<local:MainViewModel />
</ContentPage.BindingContext>
<CarouselView ItemsSource="{Binding Data}">
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout>
<Label Text="{Binding ItemTitle}" />
<StackLayout BindableLayout.ItemsSource="{Binding SubItems}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Label Text="{Binding SubItemTitle}" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
</ContentPage>
Result:
I am using a Fragment as my first screen , I have a button which Onclick has to take to me different activity.
Here is my Code:
HomeFragment.Java:
package info.androidhive.navigationdrawer.fragment;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import info.androidhive.navigationdrawer.R;
public class HomeFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private OnFragmentInteractionListener mListener;
public HomeFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* #param param1 Parameter 1.
* #param param2 Parameter 2.
* #return A new instance of fragment HomeFragment.
*/
// TODO: Rename and change types and number of parameters
public static HomeFragment newInstance(String param1, String param2) {
HomeFragment fragment = new HomeFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home, container, false);
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
// if (context instanceof OnFragmentInteractionListener) {
// mListener = (OnFragmentInteractionListener) context;
// } else {
// throw new RuntimeException(context.toString()
// + " must implement OnFragmentInteractionListener");
// }
}
#Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
}
HomeFragment.XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.androidhive.navigationdrawer.fragment.HomeFragment">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:alpha="0.3"
android:src="#drawable/ic_home_black_24dp" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</FrameLayout>
Activity.JAVA
package info.androidhive.navigationdrawer.activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import info.androidhive.navigationdrawer.R;
public class ChoseFoodCourt extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about_us);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == android.R.id.home) {
// finish the activity
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
}
I have also added the activity in manifest file.
Please help me out adding onclick listener in HomeFragment.JAVA. Not sure where to call onclick listener.
Thanks in advance.
Just use the following code from developers.android.com. There you also will find an explanation how the OnClickListener works.
public class MyActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.content_layout_id);
final Button button = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
}
});
}
}
I have a list that is dynamically generated from the view.
when the button is clicked, a new row is added, the value is entered and saved.
.zul
<zk>
<window border="normal" title="hello" viewModel="#id('vm') #init('gemalto.CreateServiceVersion')" apply="org.zkoss.bind.BindComposer">
<grid id="demoGrid"
model="#load(vm.profileList) #template((each.editingStatus) ? 'editable' : 'noneditable')">
<columns sizable="true">
<column width="160px" >Value</column>
<column width="160px" ></column>
</columns>
<rows>
<template name="editable">
<row>
<textbox id="valueTextBox"
value="#load(each.serviceProfile.valueVariable) #save(each.serviceProfile.valueVariable, before='confirm')" />
<button
image="/img/save.png" label="save"
onClick="#command('confirm', currentVariable=each)"/>
</row>
</template>
<template name="noneditable">
<row>
<label value="#load(each.serviceProfile.valueVariable)" />
</row>
</template>
</rows>
</grid>
<div align="center">
<button label="Add" image="/img/create.png" onClick="#command('onAddNew')" />
</div>
</window>
</zk>
view model
public class CreateServiceVersion extends SelectorComposer<Component> {
private boolean isEditing = false;
private boolean displayEdit = true;
private boolean isAddNew = false;
private List<ServiceProfileStatus> profileList = new ArrayList<ServiceProfileStatus>();
public List<ServiceProfileStatus> getProfileList() {
return profileList;
}
#AfterCompose
public void afterCompose() {
profileList.add(new ServiceProfileStatus(new ServiceProfile("value1"), false));
profileList.add(new ServiceProfileStatus(new ServiceProfile("value2"), false));
}
#Command
public void CrudServiceVersion() {
Executions.sendRedirect("CrudServiceVersion.zul");
}
#Command
#NotifyChange({"profileList"})
public void onAddNew() {
if (!isEditing) {
ServiceProfileStatus sps = new ServiceProfileStatus(new ServiceProfile(""), displayEdit);
profileList.add(0, sps);
isAddNew = true;
isEditing = true;
}
}
#Command
public void confirm(#BindingParam("currentVariable") ServiceProfileStatus sps) {
isEditing = false;
isAddNew = false;
sps.setEditingStatus(isEditing);
BindUtils.postNotifyChange(null,null,sps,"*");
}
}
the problem is that I add a new item, the value is copied to all others items.
I put the images to see more clearly what is happening.
imgur.com/7u7OkPG
imgur.com/mf8PUYI
imgur.com/aJpNoXM
I tested with your code and it works normally with me.
Now I changed the code a little bit :
Removed the extends SelectorComposer from your viewmodel cause that is not needed for MVVM.
Changed your 2 templates to 1 template.
Usage of your boolean in your viewmodel in the zul.
Zul :
<?xml version="1.0" encoding="UTF-8"?>
<zk>
<window border="normal" title="hello" viewModel="#id('vm') #init('be.chillworld.CreateServiceVersion')" apply="org.zkoss.bind.BindComposer">
<grid id="demoGrid" model="#load(vm.profileList)">
<columns sizable="true">
<column width="160px" >Value</column>
<column width="160px" ></column>
</columns>
<rows>
<template name="model">
<row>
<textbox value="#load(each.serviceProfile.valueVariable) #save(each.serviceProfile.valueVariable, before='confirm')" />
<button disabled="#load(not each.editingStatus)" visible="#load(each.editingStatus)" image="/img/save.png" label="save"
onClick="#command('confirm', currentVariable=each)"/>
</row>
</template>
</rows>
</grid>
<div align="center">
<button disabled="#load(vm.mayCreateNew)" label="Add" image="/img/create.png" onClick="#command('onAddNew')" />
</div>
</window>
</zk>
Viewmodel :
package be.chillworld;
import java.util.ArrayList;
import java.util.List;
import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.Executions;
/**
*
* #author chillworld */
public class CreateServiceVersion {
private boolean isEditing = false;
private List<ServiceProfileStatus> profileList = new ArrayList<ServiceProfileStatus>();
public List<ServiceProfileStatus> getProfileList() {
return profileList;
}
#AfterCompose
public void afterCompose() {
profileList.add(new ServiceProfileStatus(new ServiceProfile("value1"), false));
profileList.add(new ServiceProfileStatus(new ServiceProfile("value2"), false));
}
#Command
public void CrudServiceVersion() {
Executions.sendRedirect("CrudServiceVersion.zul");
}
#Command
#NotifyChange({"profileList","mayCreateNew"})
public void onAddNew() {
isEditing = true;
ServiceProfileStatus sps = new ServiceProfileStatus(new ServiceProfile(""), true);
profileList.add(0, sps);
}
#Command
#NotifyChange("mayCreateNew")
public void confirm(#BindingParam("currentVariable") ServiceProfileStatus sps) {
isEditing = false;
sps.setEditingStatus(isEditing);
BindUtils.postNotifyChange(null, null, sps, "*");
}
public boolean getMayCreateNew() {
return isEditing;
}
}
ServiceProfileStatus.java :
package be.chillworld;
/**
*
* #author chillworld
*/
public class ServiceProfileStatus {
private ServiceProfile serviceProfile;
private boolean editingStatus;
public ServiceProfileStatus(ServiceProfile serviceProfile, boolean editingStatus) {
this.serviceProfile = serviceProfile;
this.editingStatus = editingStatus;
}
public boolean isEditingStatus() {
return editingStatus;
}
public void setEditingStatus(boolean editingStatus) {
this.editingStatus = editingStatus;
}
public ServiceProfile getServiceProfile() {
return serviceProfile;
}
public void setServiceProfile(ServiceProfile serviceProfile) {
this.serviceProfile = serviceProfile;
}
public ServiceProfileStatus(ServiceProfile serviceProfile) {
this.serviceProfile = serviceProfile;
}
}
ServiceProfile.java :
package be.chillworld;
/**
*
* #author chillworld
*/
public class ServiceProfile {
private String valueVariable;
public ServiceProfile(String valueVariable) {
this.valueVariable = valueVariable;
}
public String getValueVariable() {
return valueVariable;
}
public void setValueVariable(String valueVariable) {
this.valueVariable = valueVariable;
}
}
I'm making an app that uses an expandable list view in a swipe tab fragment.
I'm also using the android-support v4.jar library.
And I'm getting this error. Anyone could help me?
PorTitulo.java
package com.android.bibliotecautpmovil;
import java.util.HashMap;
import java.util.List;
import com.android.bibliotecautpmovil.R;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
public class PorTitulo extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_titulo, container, false);
ExpandableListView elv = (ExpandableListView) view.findViewById(R.id.lvExp);
elv.setAdapter(new TabsListAdapter()); // **HERE I HAVE THE ERROR**
return view;
}
public class TabsListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader;
private HashMap<String, List<String>> _listDataChild;
public TabsListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
private String[] groups = { "People Names", "Dog Names", "Cat Names", "Fish Names" };
private String[][] children = {
{ "Arnold", "Barry", "Chuck", "David" },
{ "Ace", "Bandit", "Cha-Cha", "Deuce" },
{ "Fluffy", "Snuggles" },
{ "Goldy", "Bubbles" }
};
#Override`enter code here`
public int getGroupCount() {
return this._listDataHeader.size();
}
//
#Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
//
#Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
//
#Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
//
#Override`enter code here`
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
return convertView;
}
}
}
activity_main.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"
android:background="#drawable/fondoutp" >
<ExpandableListView
android:id="#+id/list"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:cacheColorHint="#00000000"/>
</LinearLayout>
list_group.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="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:background="#000000">
<TextView
android:id="#+id/lblListHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:textSize="17dp"
android:textColor="#f9f93d" />
</LinearLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="55dip"
android:orientation="vertical" >
<TextView
android:id="#+id/lblListItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="17dip"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textColor="#000000"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" />
</LinearLayout>
Glass GDK here. Trying to insert a livecard using remote views from service. I'm launching service via voice invocation. The voice command works, however it appears my service is not starting(no entries in log). Service is in android manifest. Below is code:
public class PatientLiveCardService extends Service {
private static final String LIVE_CARD_ID = "timer";
#Override
public void onCreate() {
Log.warn("oncreate");
super.onCreate();
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
publishCard(this);
return START_STICKY;
}
#Override
public void onDestroy() {
unpublishCard(this);
super.onDestroy();
}
private void publishCard(Context context) {
Log.info("inserting live card");
if (mLiveCard == null) {
String cardId = "my_card";
TimelineManager tm = TimelineManager.from(context);
mLiveCard = tm.getLiveCard(cardId);
mLiveCard.setViews(new RemoteViews(context.getPackageName(),
R.layout.activity_vitals));
Intent intent = new Intent(context, MyActivity.class);
mLiveCard.setAction(PendingIntent
.getActivity(context, 0, intent, 0));
mLiveCard.publish();
} else {
// Card is already published.
return;
}
}
private void unpublishCard(Context context) {
if (mLiveCard != null) {
mLiveCard.unpublish();
mLiveCard = null;
}
}
}
Here is AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.RECORD_AUDIO" >
</uses-permission>
<application
android:name="com.myApp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.myApp.MyActivity"
android:label="#string/app_name"
android:screenOrientation="landscape" >
</activity>
<service android:name="com.myApp.services.MyService"
android:enabled="true"
android:exported="true">
<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/voice_trigger_get_patient" />
</service>
</application>
This is a bug with XE11: the service is not started after the speech recognizer is complete.
As a workaround, you can have your voice trigger start an Activity which:
Processes the recognized speech in onResume.
Once the speech is processed, starts your Service with startService.
Calls finish to jump to the published LiveCard.