Android 共享意图后,保留最后发生的活动

Android 共享意图后,保留最后发生的活动,android,Android,我的活动流是A-->B-->C。在活动C中有股票期权。分享后,您希望在活动C中保留位置,但将转到活动A 共享意图代码 Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("image/jpeg"); sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + myImageFile.getAbsolutePath(

我的活动流是A-->B-->C。在活动C中有股票期权。分享后,您希望在活动C中保留位置,但将转到活动A

共享意图代码

 Intent sharingIntent = new Intent(Intent.ACTION_SEND);

 sharingIntent.setType("image/jpeg");

 sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + myImageFile.getAbsolutePath()));
 sharingIntent.putExtra(Intent.EXTRA_SUBJECT, ""); //"Subject here"
 sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
 sharingIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
 theCtx.startActivity(Intent.createChooser(sharingIntent, "Share via"));
这是我的活动C代码:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display);
        CommonUtils.setCommonVariables(this, this);

        findViewById(R.id.buttonBackDisplay).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                finish();
            }
        });

//      //TODO TEMP MP added to check engine in debug mode on chrome
//      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//          WebView.setWebContentsDebuggingEnabled(true);
//      }

        aviaryUtils = new AviaryUtils(this);

        myCompanyJSONObject = CommonUtils.loadCompanyJsonFile(this, CommonUtils.E_COMPANY_JSON_FILE);//Reading Company json
        if (myCompanyJSONObject != null) //if CompanyjsonObject is null then create new one
        {
            mySaveFormat = CommonUtils.getStringFromJson(myCompanyJSONObject, CommonUtils.E_COMPANY_SAVE_FORMAT, "");
        }
        myRelativeLayoutAviaryDesign=(RelativeLayout)findViewById(R.id.relativeLayoutAviaryDesign);
        myImageViewAviaryDesign=(ImageView)findViewById(R.id.imageViewAviaryDesign);

        myWebviewDisplay = (WebView) findViewById(R.id.webviewDisplay);

        myWebviewDisplay.clearCache(true);
        myWebviewDisplay.clearHistory();
        myWebviewDisplay.clearFormData();

        WebSettings webSettings = myWebviewDisplay.getSettings();
        // To enable java script on page.
        webSettings.setJavaScriptEnabled(true);


        webSettings.setAllowContentAccess(true);
        webSettings.setAllowFileAccess(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setDomStorageEnabled(true);

        //webSettings.setAllowFileAccessFromFileURLs(true);
        //webSettings.setAllowUniversalAccessFromFileURLs(true);
        //To always load page from web server, not to use resources from cache.
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);


        int currentapiVersion = Build.VERSION.SDK_INT;
        if (currentapiVersion >= Build.VERSION_CODES.JELLY_BEAN) {
            fixNewAndroid(myWebviewDisplay);
        }

        Log.d("MP111", "MP111");

        myWebviewDisplay.setWebChromeClient(new WebChromeClient() {
            // TODO
        });


        myWebviewDisplay.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                Log.d("onPageStarted()", url);
                if (url.contains("abhigna.info")) {
                    //view.stopLoading();
                    //Log.d("view.stopLoading()","stopped url:"+ url);
                    ////return;
                }
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public WebResourceResponse shouldInterceptRequest(WebView view, String url) {

                if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
                    if (url.indexOf("file:///android_asset") == 0 && url.contains("?")) {
                        String filePath = url.substring(22, url.length());
                        filePath = filePath.substring(0, filePath.indexOf("?"));
                        try {
                            InputStream is = DisplayActivity.this.getAssets().open(filePath);
                            WebResourceResponse wr = new WebResourceResponse("text/html", "Cp1252", is);
                            return wr;
                        } catch (IOException e) {
                            return null;
                        }
                    } else {
                        return null;
                    }
                } else
                    return super.shouldInterceptRequest(view, url);
            }


                    myWebviewDisplay.loadUrl(tempString);
                    return true;

                }

                return false;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
            }

            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Toast.makeText(DisplayActivity.this, "6001 - Error! " + description, Toast.LENGTH_SHORT).show();
                super.onReceivedError(view, errorCode, description, failingUrl);
            }
        });
        Log.d("MP222", "MP222");
        //root_sd = Environment.getExternalStorageDirectory().toString();
         myDataJsonPath = CommonUtils.SDCardBasePath + "/" + CommonUtils.DATA_FOLDER_NAME + "/" +
                CommonUtils.E_DATA_JSON_FILENAME;
        Log.d("Oncreate.SDCardBasePath", CommonUtils.SDCardBasePath);
        Log.d("MPOncreate_dataJsonPath", myDataJsonPath);
        //Toast.makeText(this, dataJsonPath, Toast.LENGTH_LONG).show();
        //String dataJsonPath="file://"+root_sd+"/"+ICardXpressCommonUtils.APP_FOLDER_NAME+"/Data/data.json";
        //String dataJsonPath="data1.json";
        Log.d("MP333", "MP333");
        File f = new File(myDataJsonPath);
        if (f.exists()) {
            System.out.println("Exist......");
        }

        byte[] bytes = myDataJsonPath.getBytes();
        String hexValue = "";
        for (int i = 0; i < bytes.length; i++) {

            hexValue = hexValue + byteToHex(bytes[i]);
            System.out.println("bytes[" + i + "] " +
                    (i <= 9 ? "  = " : " = ") +
                    ((int) bytes[i] < 9 ? "  " : "") +
                    (((int) bytes[i] > 9 && (int) bytes[i] <= 99) ? " " : "") +
                    bytes[i] + " : " +
                    " HEX=(0x" + byteToHex(bytes[i]) + ") : " +
                    " charValue=(" + (char) bytes[i] + ")");
        }

        System.out.println("hexValue:" + hexValue);

        Date convertedDate = new Date();
        String format = "yyMMddhhmmss";
        SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US);


        myStrUrl = getResources().getString(R.string.bundle_path) + "/" +
                CommonUtils.BMX_DEMO_FOLDER_NAME + "/index.html?" + CommonUtils.APP_QUERYSTRING + "=" +
                CommonUtils.APP_NAME + "&" + CommonUtils.CALL_TYPE_QUERYSTRING + "=" +
                CommonUtils.CALL_TYPE_EXECUTION + "&" + CommonUtils.DATA_JSON_PATH_QUERYSTRING + "=" + hexValue +
                "&t=" + sdf.format(convertedDate).toString() + "&save=" + mySaveFormat;

        Log.v("MPOnCreatestrUrl1", myStrUrl);
        final DisplayBrandMobileActivityWebAppInterface dgJavaScriptInterface = new DisplayBrandMobileActivityWebAppInterface(this);
        myWebInterfaceName = String.format("Dg%sWeb", "BrandMobile");
        myWebviewDisplay.addJavascriptInterface(dgJavaScriptInterface, myWebInterfaceName);

        myWebviewDisplay.loadUrl(myStrUrl);

    }
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_显示);
setCommonVariables(this,this);
findviewbyd(R.id.buttonBackDisplay).setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
完成();
}
});
////添加TODO TEMP MP以检查chrome上处于调试模式的引擎
//if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.KITKAT){
//WebView.setWebContentsDebuggingEnabled(true);
//      }
aviaryUtils=新的aviaryUtils(本);
myCompanyJSONObject=CommonUtils.loadCompanyJsonFile(这是CommonUtils.E_COMPANY_JSON_文件);//读取公司JSON
if(myCompanyJSONObject!=null)//如果CompanyjsonObject为null,则创建一个新的
{
mySaveFormat=CommonUtils.getStringFromJson(myCompanyJSONObject,CommonUtils.E_COMPANY_SAVE_FORMAT,”);
}
myRelativeLayoutAviaryDesign=(RelativeLayout)findViewById(R.id.relativeLayoutAviaryDesign);
myImageViewAviaryDesign=(ImageView)findViewById(R.id.imageViewAviaryDesign);
myWebviewDisplay=(WebView)findViewById(R.id.webviewDisplay);
myWebviewDisplay.clearCache(true);
myWebviewDisplay.clearHistory();
myWebviewDisplay.clearFormData();
WebSettings WebSettings=myWebviewDisplay.getSettings();
//在页面上启用java脚本。
setJavaScriptEnabled(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowFileAccess(true);
setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setDomStorageEnabled(true);
//setAllowFileAccessFromFileURLs(true);
//setAllowUniversalAccessFromFileURL(true);
//始终从web服务器加载页面,而不是使用缓存中的资源。
设置缓存模式(webSettings.LOAD\u NO\u缓存);
int currentapiVersion=Build.VERSION.SDK\u int;
if(currentapiVersion>=Build.VERSION\u CODES.JELLY\u BEAN){
fixNewAndroid(myWebviewDisplay);
}
Log.d(“MP111”、“MP111”);
myWebviewDisplay.setWebChromeClient(新的WebChromeClient()){
//待办事项
});
myWebviewDisplay.setWebViewClient(新的WebViewClient(){
@凌驾
public void onPageStarted(WebView视图、字符串url、位图favicon){
Log.d(“onPageStarted()”,url);
if(url.contains(“abhigna.info”)){
//view.stopLoading();
//Log.d(“view.stopLoading()”,“stopped url:+url”);
////返回;
}
super.onPageStarted(视图、url、favicon);
}
@凌驾
公共WebResourceResponse应InterceptRequest(WebView视图,字符串url){

如果(Build.VERSION.SDK_INT您可以通过启动活动等待
共享活动

 Intent sharingIntent = new Intent(Intent.ACTION_SEND);

 sharingIntent.setType("image/jpeg");

 sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + myImageFile.getAbsolutePath()));
 sharingIntent.putExtra(Intent.EXTRA_SUBJECT, ""); //"Subject here"
 sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
 sharingIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
 theCtx.startActivity(Intent.createChooser(sharingIntent, "Share via"), REQUEST_ID); // declare global REQUEST_ID = 999 or whatever
然后,您将在ActivityResult上收到
呼叫,在共享后做您想做的任何事情


希望这能有所帮助。

您可以通过启动“结果”活动来等待“共享活动”

 Intent sharingIntent = new Intent(Intent.ACTION_SEND);

 sharingIntent.setType("image/jpeg");

 sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + myImageFile.getAbsolutePath()));
 sharingIntent.putExtra(Intent.EXTRA_SUBJECT, ""); //"Subject here"
 sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
 sharingIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
 theCtx.startActivity(Intent.createChooser(sharingIntent, "Share via"), REQUEST_ID); // declare global REQUEST_ID = 999 or whatever
然后,您将在ActivityResult上收到
呼叫,在共享后做您想做的任何事情



希望这能有所帮助。

删除
共享内容.setFlags(Intent.FLAG\u ACTIVITY\u SINGLE\u TOP);
和tryIt将是相同的输出..是的..请给出一个如何保留最后一个活动的想法。@android1101:请发布活动
C
code。您在活动C中共享了什么?删除
共享内容.setFlags(Intent.FLAG\u ACTIVITY\u SINGLE\u TOP)
和tryIt将是相同的输出..是的..只要给出一个如何保持最后一个活动的想法。@android1101:请发布活动
C
code。你在活动C中的共享位置在哪里?结果是什么?当你从
活动C
执行此
共享意图代码
时,会发生什么?你在
活动结果中被调用了吗
?您将在
活动A
活动C
中获得结果?请将
活动C
代码和共享意图代码发布到活动C上。更新了我在活动A中所做的codeOhk。它有效..呸..谢谢:)我没有那么多的名声:D:D结果是什么?当你从
活动C
执行此
共享意图代码时,会发生什么?你在
活动结果中得到调用吗?你在
活动A
活动C
中得到结果吗?请发布
活动结果的
代码ivty C
和shareIntent代码。更新了代码OHK我在活动A中所做的工作。它有效..呸..谢谢:)我没有那么多的声誉:D:D