Initialize Script on Startup

183

Solution 1

A preferred way to execute a script during boot is to create an Upstart job. Job configuration file might go to /etc/init (system jobs) or to ~/.init (user jobs).

Upstart is an event-based replacement for the venerable System-V init introduced for the first time in Ubuntu 6.10.

You will find answers to basic questions here.

To get started go here.

Detailed documentation having zilion examples can be found here.

Solution 2

To do that you must add your script to /etc/init.d/fileName and then type this

sudo update-rc.d fileName defaults.

Don't forget to make file executable using chmod 755 fileName

Sources:

Share:
183

Related videos on Youtube

sm123
Author by

sm123

Updated on September 18, 2022

Comments

  • sm123
    sm123 over 1 year

    I have a list containing Activity-A, each Activity-A has different values inside it. However they all have the same class, which is Activity-A. When the user navigates back to the list from an activity, I store that activity in an ArrayList and retrieve it and start it as an intent when the user clicks on the same activity in the list again. However, that causes it to be re-created. I want it to be resumed from the state it was stored in the ArrayList. How can I do this?

    Edit: I've heard of the FragmentManager and how it easily stores and can retrieve fragments. However, is there something like FragmentManager for activities? Is ActivityManager like the FragmentManager?

    Edit: To clarify my question a bit more, I'm trying to:

    • Save the FragmentActivity to an ArrayList when it gets stopped
    • Resume it from the state before it was stopped.

    However, when I navigate to the FragmentActivity stored in the ArrayList, the FragmentActivity is recreated from scratch, instead of resuming from its previous state.

    I understand that I have to do something with saving its state. However, I doubt I can save all of its inside contents; there's lots of fragments in it.

    Here's the code:

    listItem.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    showActivity(id);
                }
    
    
    private void showActivity(int id) {
            ActivityA activityA = StaticLab.get(getActivity())
                    .getActivityA(id); // getActivityA simply returns the ActivityA from the ArrayList which contains the specified id
            if (activityA == null) {
                createNewActivityA()
            }
            Intent i = new Intent(getActivity(), activityA.getClass());
            startActivity(i);
    
        }
    
    • SweetWisher ツ
      SweetWisher ツ over 9 years
      can you be more specific with your query and share some code?
  • Eugene
    Eugene about 11 years
    Thanks alot, really saved me on that one. Don't have to impatiently wait for a few seconds and then initialize the script anymore.
  • sm123
    sm123 over 9 years
    Thanks, but I'm not quite sure I understand what you are saying. If you are referring to where the activities are stored, they are stored in an ArrayList. The things it contains cannot be put into an SQLite.
  • B M
    B M over 9 years
    you can try with global variable. In activity state you want to store array list? i think that can't be. you can read activity life cycle .developer.android.com/reference/android/app/Activity.html
  • sm123
    sm123 over 9 years
    I'm not quite sure what you mean by using a global variable. The class which contains the ArrayList is static, so there aren't multiple copies of it. When I navigate to the ListView, the activity calls onStop(), but when i navigate back to it via an intent, it calls onCreate() all over again, instead of onStart(), which I think may be due to using Intent.startActivity(i)
  • B M
    B M over 9 years
    please try onResume() event. onResume() to restore data previous state.
  • sm123
    sm123 over 9 years
    How do I do that? Sorry, I'm new to android programming and where I am right now, the internet is quite slow.