PrommeringsDisplay
PrommeringsDisplay

Reputation: 99

restarting app w/o closing it

I have a small little tip calculator app that works pretty well, i am trying to implement a clear button, but with the code i tried it just closes the app, how would i go about starting code over... here is what i tried below..

clearButton.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

            percentage = 0;
            output = 0;
            output1 = "";
             TextView textView = null;

            textView.clearComposingText();

            percentageInp = 0;
            billAmount = 0;

            myEditField.setText("");
            myEditField2.setText("");

            return;
        }


    });

Upvotes: 1

Views: 80

Answers (2)

tsukimi
tsukimi

Reputation: 1645

You set the textView to null then try to call a method on it so its probably force closing , that closes the app. Remove the

TextView textView = null;

To clear the

TextView textView = (TextView)findViewById(R.id.textView1);
textView.setText("");

This assumes your textview is called textView1. The way you are clearing variables now seems ok and a simple way to do it, since its a tip calculator i assume there aren't many variables to clear, so this manual way will be ok.

Upvotes: 1

user1538709
user1538709

Reputation:

You could essentially pass the former pid to start parameter to an new instance and then killd the old instance when the new instance is loaded. Use Process.GetCurrentProcess method to read the old instance pid. Pass the parameter to new instance using Arguments property in ProcessStartInfo. Then use Process.GetProcessById in new instance to get and kill th eold instance when the new instance argument is passed.

Get Process (android):

ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
List l = am.getRunningAppProcesses();

Upvotes: 1

Related Questions