Is it possible to run the selected configuration without persisting it?

Hi,

Regards to an Android Studio plugin,
I want to run the "selected/activty configuration" with temporary parameter (like setting the "launch Activity").
I managed to do it by the attached code, but the change is persisted.
Question:
  Is it possible to achieve the goal wihtout persisting it? Thanks.

--

 
public void testAction(AnActionEvent e) {
    RunManager manager = RunManager.getInstance(e.getProject());
    
RunnerAndConfigurationSettings selectedConfiguration = manager.getSelectedConfiguration();
    
RunConfiguration conf = selectedConfiguration.getConfiguration();
    if
(! (conf instanceof AndroidRunConfiguration)) {
        return;
    
}

    AndroidRunConfiguration anConf = (AndroidRunConfiguration) conf;

    // change the target Activity -- Note: it will change the stored configuration
    
anConf.setLaunchActivity("com.example.app1/com.example.app1.MainActivity");

    
Project project = e.getData(PlatformDataKeys.PROJECT);

    
ProgramRunnerUtil.executeConfiguration(project, selectedConfiguration,
            
DefaultRunExecutor.getRunExecutorInstance());
}
1 comment
Comment actions Permalink

Sorry for late reply. You can try the following: create a copy of selectedConfiguration by calling 'clone' method on it (RunnerAndConfigurationSettingsImpl implements Cloneable), then modify the copy and start it.

0

Please sign in to leave a comment.