android - Finishing an activity from service -
I am creating an app for which a connection to a MQTT server is all right, but I want to make it proof-proof more specifically, I need that when the service is unable to connect to the MQTT server, the application stops because it can not do anything I want to transmit the intention of the activity Tried, but caught the broadcast exception Not reaching after. (I've done easily Omet some code to understand)
service to handle intent () activity is required to eliminate (SelectionGrid.class) I get a log entry while holding exceptions, but the broadcast activity never goes away. Is there a better way of doing this? I was able to solve it. It came to know that I was calling the wrong activity that I really needed. The code I showed in the question is correct.
try {mqttClient.connect (); } Hold (MqttException e) {intent msgint = new intent (); msgint.setAction (constantStrings.SH_CONN_ERROR); sendBroadcast (msgint); Log D. ("McKitlog", "Error-McCattyException" + EZET Message ()); }
@Override secure zero saved create (Bundle Given Instestestate) {[...] IntentFilter Filter = New IntentFilter (); filter.addAction (constantStrings.SH_CONNERROR); Register Receiver (SH_Communication, Filter); } Broadcast receiver SH_Communication = new broadcast receiver () {@ Override public Ricoid on Risiv (Context context, intended effect) {String action = Intentkget action (); If (action.equals (constant.Strings.SH_CONN_ERROR)) {new AlertDialogkBuilder (GetApplicationContext ()) KsetTitle ( "error") Ksetmesjh ( "No connection") Ksetsin qualified (wrong) KsetPositiveButton ( "Close application ", new DialogInterface.OnClickListener () {public void onClick (DialogInterface dialog, int which) {SelectionGrid.this.finish ();}}) .setIcon (android.R.drawable.ic_dialog_alert) .show (); }}};
Comments
Post a Comment