Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2. private Button button;
  3.  
  4. @Override
  5. protected void onCreate(Bundle savedInstanceState) {
  6. super.onCreate(savedInstanceState);
  7. setContentView(R.layout.activity_main);
  8. button = (Button)findViewById(R.id.buttonid);
  9. button.setOnClickListener(new View.OnClickListener() {
  10. @Override
  11. public void onClick(View view) {
  12.  
  13. startActivity(new Intent(MainActivity.this,Main2Activity.class));
  14. }
  15. });
  16. SharedPreferences pref = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE);
  17. if(pref.getBoolean("activity_executed", false)){
  18.  
  19. } else {
  20. Intent intent = new Intent(this, Main2Activity.class);
  21. startActivity(intent);
  22. finish();
  23. SharedPreferences.Editor ed = pref.edit();
  24. ed.putBoolean("activity_executed", true);
  25. ed.commit();
  26. }
  27. }
  28. }
  29.  
  30. public class Main2Activity extends AppCompatActivity {
  31.  
  32. @Override
  33. protected void onCreate(Bundle savedInstanceState) {
  34. super.onCreate(savedInstanceState);
  35. setContentView(R.layout.activity_main2);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement