TejaReddy
TejaReddy

Reputation: 337

Intent.getType() returning null in onNewIntent(Intent intent ) method

I am trying to get Intent of mime type text/plain from other apps and store that text in a variable of type string. It is working fine from onCreate method but when i uses singleTask as launchmode and pause the app(by pressing home button) and try to share text from other app to my app, onNewIntent(Intent intent) method is getting called and intent.getType() is returning null,but same is working fine from onCreate method, I don't know why, please help. Thanks

private String sharedData="";
@Override
protected void onNewIntent(Intent intent) {

    intent = getIntent();
    String action = intent.getAction();

    String type = intent.getType();  //this method is returning null

    if(intent.ACTION_SEND.equals(action) && type!=null)
    {
        sharedData = FileHandler.handleSendText(intent);//FileHandler is class i created with contains method handleSendText
    }

    super.onNewIntent(intent);
}

Upvotes: 1

Views: 802

Answers (1)

Shaishav
Shaishav

Reputation: 5312

The call intent = getIntent(); will return you the original intent provided to the activity. Hence, it should be null. Try removing this line.

Upvotes: 1

Related Questions