Last active
June 27, 2017 14:38
-
-
Save SelvinPL/3599baab8dd9dbf50f283dd3bfe4fdfd to your computer and use it in GitHub Desktop.
Of course it will not work when Dev Options->Don't Keep Activitie is on
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package pl.selvin.completelywrongsolution; | |
| import android.app.Activity; | |
| import android.content.BroadcastReceiver; | |
| import android.content.Context; | |
| import android.content.Intent; | |
| import android.content.IntentFilter; | |
| import android.os.Bundle; | |
| import android.util.Log; | |
| import android.view.View; | |
| import android.widget.Button; | |
| public class DoNotDoThisBecauseItsStupid { | |
| public static class MainActivity extends Activity { | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| Button btn = new Button(this); | |
| btn.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| startActivity(new Intent(MainActivity.this, SecondActivity.class)); | |
| } | |
| }); | |
| btn.setText("MainActivity - open SecondActivty"); | |
| setContentView(btn); | |
| registerReceiver(broadcast_reciever, new IntentFilter("finish_activity")); | |
| } | |
| BroadcastReceiver broadcast_reciever = new BroadcastReceiver() { | |
| @Override | |
| public void onReceive(Context arg0, Intent intent) { | |
| String action = intent.getAction(); | |
| if (action.equals("finish_activity")) { | |
| Log.e("OnReceive!!", "allo, allo"); | |
| finish(); | |
| } | |
| } | |
| }; | |
| @Override | |
| protected void onDestroy() { | |
| super.onDestroy(); | |
| //It is bad to do not unregister but screw that solution is wrong so we don't do this ... it's still would not work | |
| //unregisterReceiver(broadcast_reciever); | |
| } | |
| } | |
| public static class SecondActivity extends Activity { | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| Button btn = new Button(this); | |
| btn.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| Intent intent = new Intent("finish_activity"); | |
| sendBroadcast(intent); | |
| finish(); | |
| } | |
| }); | |
| btn.setText("SecondActivity - close MAIN"); | |
| setContentView(btn); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
