How start a service (module2) from another activity (in module1) in android studio? -
i have project in android studio 2 modules: wear , mobile. in wear module have wearservice , in mobile module have handactivity. want start wearservice handactivity, pressing button. how can it? im trying use code, wasnt working.
package com.example.joe.activitytoactivity; public class wearservice extends wearablelistenerservice { public wearservice() { } @override public int onstartcommand(intent intent, int flags, int startid){ super.onstartcommand(intent, flags, startid); return start_sticky; }
}
and
package com.example.joe.activitytoactivity; public class handactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_hand); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_hand, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } public void sendmessage(view view) { intent intent = new intent(handactivity.this,com.example.joe.activitytoactivity.wearservice.class); startactivity(intent); }
}
where problem? android studio part wrong: intent(handactivity.this,com.example.joe.activitytoactivity.wearservice.class
edit:in intent, ide says: cannot resolve symbol "wearservice"
obs: sorry may english.
instead of
intent intent = new intent(handactivity.this,com.example.ewelton.activitytoactivity.wearservice.class)
try
intent intent = new intent(this,wearservice.class);
also, new activity needs declared in androidmanifest such:
<activity android:name = "com.example.joe.activitytoactivity.wearservice" android:label = "optionalname" </activity>
Comments
Post a Comment