in

What will happen if we run startActivity in a loop?


Suppose there are two apps:

  1. Tracker ( Which I am developing)
  2. SomeApplicaiton (For reference we will say this is youtube app)

Now, I want the SomeApplicaiton.apk app to always keep running even if due to some reason SomeApplicaiton crashes, I want the Tracker app to relaunch it. I have found a solution using the below code. This is working too, I want to know what will happen if I let it run for 2 to 3 days. will it make the tracker app consume more memory?

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Timer t = new Timer();
        startService(new Intent(getBaseContext(), OnClearFromRecentService.class));

        TimerTask tt = new TimerTask() {
            @Override
            public void run() {
               
                try {
                    Intent intent = getPackageManager().getLaunchIntentForPackage("com.google.android.youtube");
                    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity( intent );
                    Log.d("status","tryin to start yt");

                }catch (Exception e ){
                    Log.d("error",e.getMessage());

                }

            };
        };

        t.scheduleAtFixedRate(tt,500,5000); // try to start after 5 sec.

    }

}



Source: https://stackoverflow.com/questions/70557789/what-will-happen-if-we-run-startactivity-in-a-loop

a simple Streamlit component that allows users to select a single item from a list of options in a menu

I was programming a car simulator but whenever it comes to a ramp it suddenly stops? Code is here: