Android从Eclipse开始正确的活动 - 但不是从手机开始

时间:2012-08-27 04:54:39

标签: android eclipse android-intent android-activity manifest

当我将我的应用程序从Eclipse启动到手机时,它首先启动Launcher,然后启动我的主要活动。它成功地将变量传递给主要活动。我检查用户名是否已用toast记录。 当我直接从手机启动我的应用程序时,它直接进入主要活动; main活动将变量注册为null。

我创建了一个测试应用程序,它完全执行与此中的启动程序相同的功能;除活动名称外,其清单相同;当我从Eclipse安装它时,测试应用程序的功能与手机有关。

这是一个真正的脑筋急转弯。

以下是入门活动的代码:

public class SecureAppStarter extends Activity {


TextView report;
WebView input;
Context thisContext = this;
String thisValue, url;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.starter);
    initialize();


    WebViewClient rclient = new WebViewClient(){
        @Override
        public boolean shouldOverrideUrlLoading(WebView  view, String  url){
            return false;
        }
        @Override
        public void onLoadResource(WebView  view, String  url){ 
            input.getSettings().setJavaScriptEnabled(true);
            input.addJavascriptInterface(new CustomJavaScriptInterface(thisContext), "Android");
        }

        @Override
        public void onPageFinished(WebView view, String url){
            report.setText(""+thisValue);
            if (thisValue!= null){
                Intent passOn = new Intent("arbuckle.app.MainActivity");
                passOn.putExtra("username", thisValue);
                startActivity(passOn);
            }
        }
    };
    rclient.onPageFinished(input, url);
    input.setWebViewClient(rclient);
    input.loadUrl(url);
}


public class CustomJavaScriptInterface {
    Context mContext;

    CustomJavaScriptInterface(Context context) {

        mContext = context;
    }

    public void getValue(String value){
        thisValue = value;
    }
}

private void initialize() {
    report = (TextView) findViewById(R.id.tvViewName);
    input = (WebView) findViewById(R.id.wbWebAuth);
    url = "http://URL.of.data.com";
}
}

以下是清单:

 <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name="SecureAppStarter"
            android:label="@string/app_name"
            android:configChanges="keyboardHidden|orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
          <activity
            android:name=".ArbuckleAppActivity"
            android:label="@string/app_name"
            android:configChanges="keyboardHidden|orientation">
            <intent-filter>
                <action android:name="arbuckle.app.ArbuckleAppActivity" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

1 个答案:

答案 0 :(得分:0)

好吧我明白了。

我一直在安装/卸载应用程序的版本数周,其中主要活动是启动器。很明显,它被保存在Android缓存的某个地方,并且它正在选择要启动的主要活动,即使它不再是启动器。

所以我完全卸载了应用程序;并重新安装。现在它有效。

有人认为我破解了问题而不是解决问题吗?我是否应该期待未来的进一步问题?