Question: this code i got is from Alexander Battisti about how to make a tree from a list of data:

```
let data = [4;3;8;7;10;1;9;6;5;0;2]

type Tree<'a> = 
    | Node of Tree<'a> * 'a * Tree<'a>
    | Leaf

let rec insert tree element = 
    match element,tree with
    | x,Leaf        -> Node(Leaf,x,Leaf)
    | x,Node(l,y,r) when x <= y -> Node((insert l x),y,r)
    | x,Node(l,y,r) when x > y -> Node(l,y,(insert r x))
    | _ -> Leaf

let makeTree = List.fold insert Leaf data

```

then i want to implement this code to my binary search tree code

```
let rec BinarySearch tree element = 
    match element,tree with
    | x,Leaf   -> BinarySearch (Node(Leaf,x,Leaf)) x
    | x,Node(l,y,r) when x<=y ->
        BinarySearch l y
    | x,Node(l,y,r) when x>y ->
        BinarySearch r y
    | x,Node(l,y,r) when x=y ->
        true
    | _ -> false

```

then i use my search code like this: 

```
> BinarySearch makeTree 5;;

```

and the result is none because it's like i got an infinite looping
can someone help me? if my code is wrong, please help me to correct it, thank you

Answer: 
To expand on the issue: starting from Android 3.1, installed applications are put in "STOPPED" state. To invoke BroadcastReceiver(s) from stopped application an additional [broadcast intent flag](http://developer.android.com/reference/android/content/Intent.html#FLAG_INCLUDE_STOPPED_PACKAGES) is required.

More details: <http://developer.android.com/sdk/android-3.1.html#launchcontrols>

I created `FLAG_INCLUDE_STOPPED_PACKAGES` constant (=32) in my application (for pre-Android 3.1) and just add it to my broadcast intent `intent.addFlags(FLAG_INCLUDE_STOPPED_PACKAGES);`
> 
> Is there a reason these phones need to be restarted before the BroadcaseReceiver can pick anything up?
> 
> 
> 

Assuming that your application has its `BroadcastReceiver` registered in the manifest for the `PHONE_STATE` broadcast, it should work immediately upon install. If it does not, it feels like a buggy ROM to me.

> 
> Is there a way I can detect if it isn't running and manually "start" the BroadcaseReceiver?
> 
> 
> 

No, mostly because it's not running, usually, even when things are working. An instance of your `BroadcastReceiver` is created at the point of the `Intent` - `<intent-filter>` match, it is called with `onReceive()`, and the `BroadcastReceiver` is disposed of once `onReceive()` returns.