Reputation: 11
I'm trying to create a custom card in android wear app (this card is created by WearableListenerService),my problem is when the card appears and my application is closed the button on the card does not work, but when the application is running the button works well. I stated to develop to android recently and I 'm not getting fix the problem , someone could help me ? Thank you very much
public class ListenerService extends WearableListenerService {
private static final String _MESSAGE_PATH = "/message_path";
private static final String _NOTIFICATION_NUMBER = "/notificationNumber";
private static Context _context;
public void onMessageReceived(MessageEvent messageEvent) {
switch(messageEvent.getPath()){
case _MESSAGE_PATH:
break;
case _NOTIFICATION_NUMBER:
_context = getBaseContext();
new Thread(tCards).start();
break;
default:
super.onMessageReceived(messageEvent);
break;
}
}
private Runnable tCards = new Runnable(){
public void run() {
Intent _Card = new Intent();
_Card.setClass(map, CardCall.class);
_Card.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
_context.startActivity(_Card);
}
};
}
public class CardCall extends Activity {
ClientAction client = ClientAction.getInstance();
BoxInsetLayout _boxBK;
ImageButton imgCancel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cards_main);
CardScrollView cardScrollView =
(CardScrollView) findViewById(R.id.card_scroll_view);
cardScrollView.setCardGravity(Gravity.BOTTOM);
imgCancel = (ImageButton) findViewById(R.id.btnStopSong);
_boxBK = (BoxInsetLayout) findViewById(R.id.background);
_boxBK.setBackgroundColor(Color.BLUE);
imgCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new TaskStop().execute();
}
});
}
private class TaskStop extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
client.StopSong("");
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.wearable.view.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/background"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.wearable.view.CardScrollView
android:id="@+id/card_scroll_view"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_box="bottom">
<android.support.wearable.view.CardFrame
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:paddingLeft="5dp">
<TextView
android:fontFamily="sans-serif-light"
android:layout_height="wrap_content"
android:layout_width="100dp"
android:text="Text titulo"
android:textColor="@color/black"
android:textSize="20sp"/>
<TextView
android:fontFamily="sans-serif-light"
android:layout_height="wrap_content"
android:text="textDescricao"
android:textColor="@color/black"
android:layout_width="100dp"
android:textSize="14sp"/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/btnStopSong"
android:src="@drawable/ic_end_white_36dp"
android:background="@drawable/button_round"
android:layout_gravity="bottom" />
</LinearLayout>
</android.support.wearable.view.CardFrame>
</android.support.wearable.view.CardScrollView>
</android.support.wearable.view.BoxInsetLayout>
</RelativeLayout>
Upvotes: 1
Views: 406